weicd
2022-12-16 198557d84b980b47e865888310dd6e8aaffbea77
考勤记录
16 files added
9 files modified
1551 ■■■■■ changed files
eladmin-master/eladmin-system/pom.xml 5 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/domain/Attendance.java 103 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/repository/AttendanceRepository.java 40 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/rest/AttendanceController.java 100 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/AttendanceService.java 83 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/dto/AttendanceDto.java 75 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/dto/AttendanceQueryCriteria.java 55 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java 183 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/mapstruct/AttendanceMapper.java 32 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/constant/Constant.java 37 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/OpaiDingTalkService.java 21 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/dto/OapiDingTalkAccessToken.java 16 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/dto/OapiDingTalkRecordResult.java 38 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/OpaiDingTalkServiceImpl.java 127 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/OapiDingTalkMethod.java 251 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/User.java 6 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java 7 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java 7 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/UserService.java 6 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java 4 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java 12 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/api/attendance/attendance.js 36 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/api/system/user.js 9 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/utils/constant.js 37 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/views/attendance/attendance/index.vue 261 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/pom.xml
@@ -86,6 +86,11 @@
            <artifactId>oshi-core</artifactId>
            <version>6.1.4</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>alibaba-dingtalk-service-sdk</artifactId>
            <version>2.0.0</version>
        </dependency>
    </dependencies>
    <!-- 打包 -->
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/domain/Attendance.java
New file
@@ -0,0 +1,103 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.base.BaseEntity;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://eladmin.vip
* @description /
* @author wcd
* @date 2022-12-14
**/
@Entity
@Data
@Table(name="attendance")
public class Attendance extends BaseEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "ID")
    private Long id;
    @Column(name = "`user_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "用户ID")
    private Long userId;
    @Column(name = "`attendance_date`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "考勤日期")
    private Timestamp attendanceDate;
    @Column(name = "`rostering_work_start_time`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "排班工作开始时间")
    private Timestamp rosteringWorkStartTime;
    @Column(name = "`actual_work_start_time`")
    @ApiModelProperty(value = "实际工作开始时间")
    private Timestamp actualWorkStartTime;
    @Column(name = "`start_location_results`")
    @ApiModelProperty(value = "开始位置结果")
    private String startLocationResults;
    @Column(name = "`start_clock_results`")
    @ApiModelProperty(value = "开始打卡结果")
    private String startClockResults;
    @Column(name = "`rostering_work_end_time`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "排班工作结束时间")
    private Timestamp rosteringWorkEndTime;
    @Column(name = "`actual_work_end_time`")
    @ApiModelProperty(value = "实际工作结束时间")
    private Timestamp actualWorkEndTime;
    @Column(name = "`end_location_results`")
    @ApiModelProperty(value = "结束位置结果")
    private String endLocationResults;
    @Column(name = "`end_clock_results`")
    @ApiModelProperty(value = "结束打卡结果")
    private String endClockResults;
    @Column(name = "`date_type`",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "日期类型")
    private String dateType;
    @Column(name = "`remarks`")
    @ApiModelProperty(value = "备注")
    private String remarks;
    public void copy(Attendance source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/repository/AttendanceRepository.java
New file
@@ -0,0 +1,40 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.repository;
import me.zhengjie.modules.attendance.domain.Attendance;
import me.zhengjie.modules.attendance.service.dto.AttendanceDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @website https://eladmin.vip
* @author wcd
* @date 2022-12-14
**/
public interface AttendanceRepository extends JpaRepository<Attendance, Long>, JpaSpecificationExecutor<Attendance> {
    /** 根据用户和日期查询考勤记录对象 */
    @Query(value = "SELECT * from attendance WHERE user_id = ? and attendance_date = ? " , nativeQuery = true)
    Attendance findAllByUserIdAndAttendanceDate(Long userId, String baseDate);
    /** 根据员工姓名模糊查询 */
    @Query(value = "SELECT * from attendance WHERE  " , nativeQuery = true)
    List<AttendanceDto> findByUserNameLike(String userName);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/rest/AttendanceController.java
New file
@@ -0,0 +1,100 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.rest;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.attendance.domain.Attendance;
import me.zhengjie.modules.attendance.repository.AttendanceRepository;
import me.zhengjie.modules.attendance.service.AttendanceService;
import me.zhengjie.modules.attendance.service.dto.AttendanceDto;
import me.zhengjie.modules.attendance.service.dto.AttendanceQueryCriteria;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @author wcd
* @date 2022-12-14
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "考勤记录管理")
@RequestMapping("/api/attendance")
public class AttendanceController {
    private final AttendanceService attendanceService;
    private final AttendanceRepository attendanceRepository;
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('attendance:download')")
    public void exportAttendance(HttpServletResponse response, AttendanceQueryCriteria criteria) throws IOException {
        attendanceService.download(attendanceService.queryAll(criteria), response);
    }
    @GetMapping
    @Log("查询考勤记录")
    @ApiOperation("查询考勤记录")
    @PreAuthorize("@el.check('attendance:list')")
    public ResponseEntity<Object> queryAttendance(AttendanceQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(attendanceService.queryAll(criteria,pageable),HttpStatus.OK);
    }
    @GetMapping(value = "/all")
    @Log("查询考勤记录")
    @ApiOperation("查询考勤记录")
    @PreAuthorize("@el.check('attendance:list')")
    public ResponseEntity<Object> queryAttendance(AttendanceQueryCriteria criteria){
        return new ResponseEntity<>(attendanceService.queryAll(criteria),HttpStatus.OK);
    }
    @PostMapping
    @Log("新增考勤记录")
    @ApiOperation("新增考勤记录")
    @PreAuthorize("@el.check('attendance:add')")
    public ResponseEntity<Object> createAttendance(@Validated @RequestBody Attendance resources){
        return new ResponseEntity<>(attendanceService.create(resources),HttpStatus.CREATED);
    }
    @PutMapping
    @Log("修改考勤记录")
    @ApiOperation("修改考勤记录")
    @PreAuthorize("@el.check('attendance:edit')")
    public ResponseEntity<Object> updateAttendance(@Validated @RequestBody Attendance resources){
        attendanceService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    @DeleteMapping
    @Log("删除考勤记录")
    @ApiOperation("删除考勤记录")
    @PreAuthorize("@el.check('attendance:del')")
    public ResponseEntity<Object> deleteAttendance(@RequestBody Long[] ids) {
        attendanceService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/AttendanceService.java
New file
@@ -0,0 +1,83 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.service;
import me.zhengjie.modules.attendance.domain.Attendance;
import me.zhengjie.modules.attendance.service.dto.AttendanceDto;
import me.zhengjie.modules.attendance.service.dto.AttendanceQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @description 服务接口
* @author wcd
* @date 2022-12-14
**/
public interface AttendanceService {
    /**
    * 查询数据分页
    * @param criteria 条件
    * @param pageable 分页参数
    * @return Map<String,Object>
    */
    Map<String,Object> queryAll(AttendanceQueryCriteria criteria, Pageable pageable);
    /**
    * 查询所有数据不分页
    * @param criteria 条件参数
    * @return List<AttendanceDto>
    */
    List<AttendanceDto> queryAll(AttendanceQueryCriteria criteria);
    /**
     * 根据ID查询
     * @param id ID
     * @return AttendanceDto
     */
    AttendanceDto findById(Long id);
    /**
    * 创建
    * @param resources /
    * @return AttendanceDto
    */
    AttendanceDto create(Attendance resources);
    /**
    * 编辑
    * @param resources /
    */
    void update(Attendance resources);
    /**
    * 多选删除
    * @param ids /
    */
    void deleteAll(Long[] ids);
    /**
    * 导出数据
    * @param all 待导出的数据
    * @param response /
    * @throws IOException /
    */
    void download(List<AttendanceDto> all, HttpServletResponse response) throws IOException;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/dto/AttendanceDto.java
New file
@@ -0,0 +1,75 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.service.dto;
import lombok.Data;
import me.zhengjie.base.BaseDTO;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://eladmin.vip
* @description /
* @author wcd
* @date 2022-12-14
**/
@Data
public class AttendanceDto extends BaseDTO implements Serializable {
    /** ID */
    private Long id;
    /** 用户ID */
    private Long userId;
    /** 考勤日期 */
    private Timestamp attendanceDate;
    /** 排班工作开始时间 */
    private Timestamp rosteringWorkStartTime;
    /** 实际工作开始时间 */
    private Timestamp actualWorkStartTime;
    /** 开始位置结果 */
    private String startLocationResults;
    /** 开始打卡结果 */
    private String startClockResults;
    /** 排班工作结束时间 */
    private Timestamp rosteringWorkEndTime;
    /** 实际工作结束时间 */
    private Timestamp actualWorkEndTime;
    /** 结束位置结果 */
    private String endLocationResults;
    /** 结束打卡结果 */
    private String endClockResults;
    /** 日期类型 */
    private String dateType;
    /** 备注 */
    private String remarks;
    /** 员工姓名 */
    private String userName;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/dto/AttendanceQueryCriteria.java
New file
@@ -0,0 +1,55 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.util.List;
import me.zhengjie.annotation.Query;
/**
* @website https://eladmin.vip
* @author wcd
* @date 2022-12-14
**/
@Data
public class AttendanceQueryCriteria{
    /** 精确查询姓名 */
    @Query
    private Long userId;
    /** 精确时间查询 */
    @Query
    private String attendanceDate;
    /* 开始位置精确查询 */
    @Query(type = Query.Type.EQUAL, propName = "startLocationResults")
    private String startLocationResults;
    /* 结束位置精确查询 */
    @Query(type = Query.Type.EQUAL, propName = "endLocationResults")
    private String endLocationResults;
    /* 开始打卡精确查询 */
    @Query(type = Query.Type.EQUAL, propName = "startClockResults")
    private String startClockResults;
    /* 结束打卡精确查询 */
    @Query(type = Query.Type.EQUAL, propName = "endClockResults")
    private String endClockResults;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java
New file
@@ -0,0 +1,183 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.service.impl;
import me.zhengjie.modules.attendance.domain.Attendance;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.attendance.repository.AttendanceRepository;
import me.zhengjie.modules.attendance.service.AttendanceService;
import me.zhengjie.modules.attendance.service.dto.AttendanceDto;
import me.zhengjie.modules.attendance.service.dto.AttendanceQueryCriteria;
import me.zhengjie.modules.attendance.service.mapstruct.AttendanceMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.function.Function;
/**
* @website https://eladmin.vip
* @description 服务实现
* @author wcd
* @date 2022-12-14
**/
@Service
@RequiredArgsConstructor
public class AttendanceServiceImpl implements AttendanceService {
    private final AttendanceRepository attendanceRepository;
    private final AttendanceMapper attendanceMapper;
    private final UserRepository userRepository;
    @Override
    public Map<String,Object> queryAll(AttendanceQueryCriteria criteria, Pageable pageable){
        Page<Attendance> page = attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
        //将实体转换为Dto(重写)
        Function<Attendance, AttendanceDto> func = new Function<Attendance, AttendanceDto>(){
            @Override
            public AttendanceDto apply(Attendance attendance) {
                // 将实体类转换成DTO
                AttendanceDto attendanceDto = attendanceMapper.toDto(attendance);
                //查询用户信息
                User user = userRepository.findById(attendanceDto.getUserId()).orElseGet(User::new);
                attendanceDto.setUserName(user.getNickName());
                return attendanceDto;
            }
        };
        return PageUtil.toPage(page.map(func));
    }
    @Override
    public List<AttendanceDto> queryAll(AttendanceQueryCriteria criteria){
        return attendanceMapper.toDto(attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
    }
    @Override
    @Transactional
    public AttendanceDto findById(Long id) {
        Attendance attendance = attendanceRepository.findById(id).orElseGet(Attendance::new);
        ValidationUtil.isNull(attendance.getId(),"Attendance","id",id);
        return attendanceMapper.toDto(attendance);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AttendanceDto create(Attendance resources) {
        return attendanceMapper.toDto(attendanceRepository.save(resources));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Attendance resources) {
        Attendance attendance = attendanceRepository.findById(resources.getId()).orElseGet(Attendance::new);
        ValidationUtil.isNull( attendance.getId(),"Attendance","id",resources.getId());
        attendance.copy(resources);
        attendanceRepository.save(attendance);
    }
    @Override
    public void deleteAll(Long[] ids) {
        for (Long id : ids) {
            attendanceRepository.deleteById(id);
        }
    }
    @Override
    public void download(List<AttendanceDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (AttendanceDto attendance : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("员工", attendance.getUserName());
            map.put("考勤日期", attendance.getAttendanceDate());
            map.put("排班工作开始时间", attendance.getRosteringWorkStartTime());
            map.put("实际工作开始时间", attendance.getActualWorkStartTime());
            //开始位置判断
            if(ObjectUtils.isNotEmpty(attendance.getStartLocationResults()) && attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_NORMAL)) {
                map.put("开始位置结果","范围内");
            } else if(ObjectUtils.isNotEmpty(attendance.getStartLocationResults()) && attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_OUTSIDE)) {
                map.put("开始位置结果","范围外");
            } else{
                map.put("开始位置结果","未打卡");
            }
            //开始打卡判断
            if(ObjectUtils.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) {
                map.put("开始打卡结果","等待");
            } else if(ObjectUtils.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NORMAL)){
                map.put("开始打卡结果","正常");
            } else if(ObjectUtils.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)){
                map.put("开始打卡结果","缺卡");
            } else if(ObjectUtils.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT)){
                map.put("开始打卡结果","外出");
            } else if(ObjectUtils.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)){
                map.put("开始打卡结果","出差");
            } else if(ObjectUtils.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LEAVE)){
                map.put("开始打卡结果","请假");
            }
            map.put("排班工作结束时间", attendance.getRosteringWorkEndTime());
            map.put("实际工作结束时间", attendance.getActualWorkEndTime());
            //结束位置判断
            if(ObjectUtils.isNotEmpty(attendance.getEndLocationResults()) && attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_NORMAL)) {
                map.put("结束位置结果","范围内");
            } else if(ObjectUtils.isNotEmpty(attendance.getEndLocationResults()) && attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_OUTSIDE)) {
                map.put("结束位置结果","范围外");
            } else{
                map.put("结束位置结果","未打卡");
            }
            //结束打卡判断
            if(ObjectUtils.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) {
                map.put("结束打卡结果","等待");
            } else if(ObjectUtils.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NORMAL)){
                map.put("结束打卡结果","正常");
            } else if(ObjectUtils.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)){
                map.put("结束打卡结果","缺卡");
            } else if(ObjectUtils.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT)){
                map.put("结束打卡结果","外出");
            } else if(ObjectUtils.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)){
                map.put("结束打卡结果","出差");
            } else if(ObjectUtils.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LEAVE)){
                map.put("结束打卡结果","请假");
            }
            //日期类型判断
            if(attendance.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){
                map.put("日期类型","工作日");
            } else if(attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)){
                map.put("日期类型","节假日(串休)");
            } else{
                map.put("日期类型","节假日(法定)");
            }
            map.put("备注", attendance.getRemarks());
            map.put("创建者", attendance.getCreateBy());
            map.put("创建时间", attendance.getCreateTime());
            map.put("更新者", attendance.getUpdateBy());
            map.put("更新时间", attendance.getUpdateTime());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/mapstruct/AttendanceMapper.java
New file
@@ -0,0 +1,32 @@
/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.attendance.service.mapstruct;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.attendance.domain.Attendance;
import me.zhengjie.modules.attendance.service.dto.AttendanceDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @website https://eladmin.vip
* @author wcd
* @date 2022-12-14
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AttendanceMapper extends BaseMapper<AttendanceDto, Attendance> {
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/constant/Constant.java
New file
@@ -0,0 +1,37 @@
package me.zhengjie.modules.constant;
public class Constant {
    // 日期类型
    public static final String DATE_TYPE = "date_type";
    // 日期类型:工作日
    public static final String DATE_TYPE_WEEKDAY = "date_type_weekday";
    // 日期类型:节假日(法定)
    public static final String DATE_TYPE_LEGAL_HOLIDAYS = "date_type_legal_holid";
    // 日期类型:节假日(串休)
    public static final String DATE_TYPE_HOLIDAYS = "date_type_holidays";
    //考勤状态
    public static final String ATTENDANCE_STATE = "attendance_state";
    //考勤状态: 等待
    public static final String ATTENDANCE_STATE_WAITFOR = "attendance_state_waitFor";
    //考勤状态: 正常
    public static final String ATTENDANCE_STATE_NORMAL = "attendance_state_normal";
    //考勤状态: 缺卡
    public static final String ATTENDANCE_STATE_NOTSIGNED = "attendance_state_notSigned";
    //考勤状态: 外出
    public static final String ATTENDANCE_STATE_GOOUT = "attendance_state_goOut";
    //考勤状态: 出差
    public static final String ATTENDANCE_STATE_BUSINESS = "attendance_state_business";
    //考勤状态: 请假
    public static final String ATTENDANCE_STATE_LEAVE = "attendance_state_leave";
    //考勤位置状态
    public static final String LOCATION_RESULTS = "location_results";
    // 考勤位置状态: 范围内
    public static final String LOCATION_RESULTS_NORMAL = "location_results_normal";
    // 考勤位置状态: 范围外
    public static final String LOCATION_RESULTS_OUTSIDE = "location_results_outside";
    // 考勤位置状态: 未打卡
    public static final String LOCATION_RESULTS_NOTSIGNED = "location_results_notSigned";
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/OpaiDingTalkService.java
New file
@@ -0,0 +1,21 @@
package me.zhengjie.modules.quartz.service;
import me.zhengjie.modules.quartz.service.dto.OapiDingTalkAccessToken;
import me.zhengjie.modules.quartz.service.dto.OapiDingTalkRecordResult;
import java.util.List;
/**
 * @author zlh
 * @date 2022-02-23
 */
public interface OpaiDingTalkService {
    // 获取token
    OapiDingTalkAccessToken getAccessToken() throws Exception;
    //获取数据
    List<OapiDingTalkRecordResult> getAttendanceList(List<OapiDingTalkRecordResult> oapiDingTalkRecordResultList, String access_token, String workDate, List<String> userIdList, Long offset, Long limit) throws Exception;
    void sendNotice(List<String> userIdList, String title, String content, String type) throws Exception;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/dto/OapiDingTalkAccessToken.java
New file
@@ -0,0 +1,16 @@
package me.zhengjie.modules.quartz.service.dto;
import lombok.Data;
@Data
public class OapiDingTalkAccessToken {
    private Integer errcode;
    private String errmsg;
    private String accessToken;
    private Integer expiresIn;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/dto/OapiDingTalkRecordResult.java
New file
@@ -0,0 +1,38 @@
package me.zhengjie.modules.quartz.service.dto;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class OapiDingTalkRecordResult {
    private Integer id;
    private String sourceType;
    private Timestamp baseCheckTime;
    private Timestamp userCheckTime;
    private String procInstId;
    private Integer approveId;
    private String locationResult;
    private String timeResult;
    private String checkType;
    private String userId;
    private Timestamp workDate;
    private Integer recordId;
    private Integer planId;
    private Integer groupId;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/OpaiDingTalkServiceImpl.java
New file
@@ -0,0 +1,127 @@
package me.zhengjie.modules.quartz.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiAttendanceListRequest;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.dingtalk.api.response.OapiAttendanceListResponse;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.quartz.service.OpaiDingTalkService;
import me.zhengjie.modules.quartz.service.dto.OapiDingTalkAccessToken;
import me.zhengjie.modules.quartz.service.dto.OapiDingTalkRecordResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.List;
/**
 * @author zlh
 * @date 2022-02-23
 */
@RequiredArgsConstructor
@Service(value = "opaiDingTalkService")
public class OpaiDingTalkServiceImpl implements OpaiDingTalkService {
    private final String appkey = "dingqcailhf40maaaibg";
    private final String appsecret = "tAsp4xCPcLDCVY_SGIO_wVfQf_u2s0QQdNlBLuZD2DKwLBos9VVSdpZgnfEndDlW";
    private final Long agentId = 1455808586L;
    @Override
    public OapiDingTalkAccessToken getAccessToken() throws Exception {
        DingTalkClient clientToken = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        OapiGettokenRequest request = new OapiGettokenRequest();
        request.setAppkey(appkey);
        request.setAppsecret(appsecret);
        request.setHttpMethod("GET");
        OapiGettokenResponse response = clientToken.execute(request);
        JSONObject jsonObjectToken = JSONObject.parseObject(response.getBody());
        OapiDingTalkAccessToken oapiDingTalkAccessToken = new OapiDingTalkAccessToken();
        oapiDingTalkAccessToken.setErrcode(jsonObjectToken.getInteger("errcode"));
        oapiDingTalkAccessToken.setErrmsg(jsonObjectToken.getString("errmsg"));
        oapiDingTalkAccessToken.setAccessToken(jsonObjectToken.getString("access_token"));
        oapiDingTalkAccessToken.setExpiresIn(jsonObjectToken.getInteger("expires_in"));
        return oapiDingTalkAccessToken;
    }
    @Override
    public List<OapiDingTalkRecordResult> getAttendanceList(List<OapiDingTalkRecordResult> oapiDingTalkRecordResultList, String access_token, String workDate, List<String> userIdList, Long offset, Long limit) throws Exception {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/attendance/list");
        OapiAttendanceListRequest request = new OapiAttendanceListRequest();
        request.setWorkDateFrom(workDate);
        request.setWorkDateTo(workDate);
        request.setUserIdList(userIdList);
        request.setOffset(offset);
        request.setLimit(limit);
        OapiAttendanceListResponse rsp = client.execute(request, access_token);
        JSONObject jsonObject = JSONObject.parseObject(rsp.getBody());
        if (0 == jsonObject.getInteger("errcode")) {
            JSONArray recordresult = jsonObject.getJSONArray("recordresult");
            for (int i = 0; i < recordresult.size(); i++) {
                OapiDingTalkRecordResult oapiDingTalkRecordResult = new OapiDingTalkRecordResult();
                JSONObject result = recordresult.getJSONObject(i);
                oapiDingTalkRecordResult.setId(result.getInteger("id"));
                oapiDingTalkRecordResult.setSourceType(result.getString("sourceType"));
                oapiDingTalkRecordResult.setBaseCheckTime((Timestamp) result.getTimestamp("baseCheckTime"));
                oapiDingTalkRecordResult.setUserCheckTime((Timestamp) result.getTimestamp("userCheckTime"));
                oapiDingTalkRecordResult.setProcInstId(result.getString("procInstId"));
                oapiDingTalkRecordResult.setApproveId(result.getInteger("approveId"));
                oapiDingTalkRecordResult.setLocationResult(result.getString("locationResult"));
                oapiDingTalkRecordResult.setTimeResult(result.getString("timeResult"));
                oapiDingTalkRecordResult.setCheckType(result.getString("checkType"));
                oapiDingTalkRecordResult.setUserId(result.getString("userId"));
                oapiDingTalkRecordResult.setWorkDate((Timestamp) result.getTimestamp("workDate"));
                oapiDingTalkRecordResult.setRecordId(result.getInteger("recordId"));
                oapiDingTalkRecordResult.setPlanId(result.getInteger("planId"));
                oapiDingTalkRecordResult.setGroupId(result.getInteger("groupId"));
                oapiDingTalkRecordResultList.add(oapiDingTalkRecordResult);
            }
            if (jsonObject.getBoolean("hasMore") == true) {
                this.getAttendanceList(oapiDingTalkRecordResultList, access_token, workDate, userIdList, offset + 1, limit);
            } else {
                return oapiDingTalkRecordResultList;
            }
        } else if (1 == jsonObject.getInteger("errcode")) {
            this.getAttendanceList(oapiDingTalkRecordResultList, access_token, workDate, userIdList, offset + 1, limit);
        } else {
            return oapiDingTalkRecordResultList;
        }
        return oapiDingTalkRecordResultList;
    }
    @Override
    public void sendNotice(List<String> userIdList, String title, String content, String type) throws Exception {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
        OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
        request.setAgentId(agentId);
        request.setUseridList(StringUtils.join(userIdList, ","));
        request.setToAllUser(false);
        OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
        if ("markdown".equals(type)) {
            msg.setMsgtype("markdown");
            msg.setMarkdown(new OapiMessageCorpconversationAsyncsendV2Request.Markdown());
            msg.getMarkdown().setText(content);
            msg.getMarkdown().setTitle(title);
        }
        if ("card".equals(type)) {
            msg.setActionCard(new OapiMessageCorpconversationAsyncsendV2Request.ActionCard());
            msg.getActionCard().setTitle(title);
            msg.getActionCard().setMarkdown(content);
            msg.getActionCard().setSingleTitle("详情");
            msg.getActionCard().setSingleUrl("http://pms.yhzhg.cn/");
            msg.setMsgtype("action_card");
        }
        request.setMsg(msg);
        OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(request, getAccessToken().getAccessToken());
//        System.out.println(rsp.getBody());
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/OapiDingTalkMethod.java
New file
@@ -0,0 +1,251 @@
package me.zhengjie.modules.quartz.task;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.attendance.domain.Attendance;
import me.zhengjie.modules.attendance.repository.AttendanceRepository;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.quartz.service.dto.OapiDingTalkAccessToken;
import me.zhengjie.modules.quartz.service.OpaiDingTalkService;
import me.zhengjie.modules.quartz.service.dto.OapiDingTalkRecordResult;
import me.zhengjie.modules.system.domain.SysConfigHoliday;
import me.zhengjie.modules.system.domain.SysRostering;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.SysConfigHolidayRepository;
import me.zhengjie.modules.system.repository.SysRosteringRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
 * 钉钉定时任务(取考勤记录)
 */
@Slf4j
@Component
@Async
public class OapiDingTalkMethod {
    private final AttendanceRepository attendanceRepository;
    private final UserRepository userRepository;
    private final SysConfigHolidayRepository sysConfigHolidayRepository;
    private final OpaiDingTalkService opaiDingTalkService;
    private final SysRosteringRepository sysRosteringRepository;
    public OapiDingTalkMethod(AttendanceRepository attendanceRepository, UserRepository userRepository, SysConfigHolidayRepository sysConfigHolidayRepository, OpaiDingTalkService opaiDingTalkService, SysRosteringRepository sysRosteringRepository) {
        this.attendanceRepository = attendanceRepository;
        this.userRepository = userRepository;
        this.sysConfigHolidayRepository = sysConfigHolidayRepository;
        this.opaiDingTalkService = opaiDingTalkService;
        this.sysRosteringRepository = sysRosteringRepository;
    }
    /**
     * 每天0点执行,新增用户考勤信息
     * @throws Exception
     */
    public void getDingTalkAttendanceList() throws Exception {
        //查询状态正常的员工
        List<User> userList = getUserList();
        //获取今天时间
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String todayDate = df.format(new Date());
        //查询节假日表是否有记录
        SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(todayDate);
           if(ObjectUtils.isEmpty(sysConfigHoliday)){
                //获取当前时间
                Calendar calTodayDay = Calendar.getInstance();
                calTodayDay.setTime(Timestamp.valueOf(todayDate + " 00:00:00"));
                //判断今天是否不是周末
                if (calTodayDay.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY || calTodayDay.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
                    //遍历在职员工向考勤记录添加数据
                    for (User user : userList){
                        //查询当前用户的排班
                        SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getRosteringId());
                        //查询考勤记录是否存在
                        Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), todayDate);
                        if (ObjectUtil.isEmpty(attendance)) {
                            attendance = new Attendance();
                        }
                        attendance.setUserId(user.getId());
                        Date date = df.parse(todayDate);
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String today=sdf.format(date);
                        attendance.setAttendanceDate(Timestamp.valueOf(today));
                        attendance.setStartClockResults(Constant.ATTENDANCE_STATE_WAITFOR);
                        attendance.setEndClockResults(Constant.ATTENDANCE_STATE_WAITFOR);
                        attendance.setRosteringWorkStartTime(Timestamp.valueOf(todayDate + " " + dateTimeFormatter.format(sysRostering.getWorkStartTime())));
                        attendance.setRosteringWorkEndTime(Timestamp.valueOf(todayDate + " " + dateTimeFormatter.format(sysRostering.getWorkEndTime())));
                        attendance.setDateType(Constant.DATE_TYPE_WEEKDAY);
                        attendanceRepository.save(attendance);
                    }
                }
           }
    }
    /**
     * 中午12点30执行定时任务
     * @throws Exception
     */
    public void getDingTalkAttendanceListOfNoon() throws Exception {
        //查询状态正常的员工
        List<User> userList = getUserList();
        //获取今天时间
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String todayDate = df.format(new Date());
        //获取钉钉 Token
        OapiDingTalkAccessToken oapiDingTalkAccessToken = opaiDingTalkService.getAccessToken();
        // errcode = 0,表示正常返回
        if(0 == oapiDingTalkAccessToken.getErrcode()){
            //查询节假日表是否有记录
            SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(todayDate);
            if(ObjectUtils.isEmpty(sysConfigHoliday)){
                //获取当前时间
                Calendar calTodayDay = Calendar.getInstance();
                calTodayDay.setTime(Timestamp.valueOf(todayDate + " 00:00:00"));
                //判断今天是否不是周末
                if (calTodayDay.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY || calTodayDay.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
                    //遍历在职员工向考勤记录添加数据
                    for (User user : userList) {
                        //用户钉钉id
                        List<String> userDinDingList = new ArrayList<>();
                        userDinDingList.add(user.getDingding());
                        //查询当前用户的排班
                        SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getRosteringId());
                        //查询考勤记录是否存在
                        Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), todayDate);
                        //访问钉钉获取数据
                        List<OapiDingTalkRecordResult> oapiDingTalkRecordResultList = new ArrayList<>();
                        oapiDingTalkRecordResultList = opaiDingTalkService.getAttendanceList(oapiDingTalkRecordResultList, oapiDingTalkAccessToken.getAccessToken(), todayDate + " 00:00:00", userDinDingList, 0l, 50l);
                        //判断钉钉是否获取到数据
                        if (oapiDingTalkRecordResultList.size() != 0) {
                            for (OapiDingTalkRecordResult oapiDingTalkRecordResult : oapiDingTalkRecordResultList) {
                                if ("NotSigned".equals(oapiDingTalkRecordResult.getTimeResult())) {
                                    oapiDingTalkRecordResult.setUserCheckTime(null);
                                }
                                if ("OnDuty".equals(oapiDingTalkRecordResult.getCheckType())) {
                                    //判断状态
                                    String result = ObjectUtils.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : Constant.ATTENDANCE_STATE_NORMAL;
                                    attendance.setStartClockResults(result);
                                    attendance.setStartLocationResults(setLocationResults(oapiDingTalkRecordResult.getLocationResult()));
                                    attendance.setActualWorkStartTime(oapiDingTalkRecordResult.getUserCheckTime());
                                }
                            }
                            attendanceRepository.save(attendance);
                            // 判断修改考勤状态
                            updateRecord(user,todayDate);
                        }
                    }
                }
            }
        }
    }
    /**
     * 晚上02:30定时任务
     */
    public void getDingTalkAttendanceListOfNight() throws Exception {
        //查询状态正常的员工
        List<User> userList = getUserList();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        //获取钉钉 Token
        OapiDingTalkAccessToken oapiDingTalkAccessToken = opaiDingTalkService.getAccessToken();
        // errcode = 0,表示正常返回
        if(0 == oapiDingTalkAccessToken.getErrcode()){
            //获取昨天时间
            Calendar calYesterDay = Calendar.getInstance();
            calYesterDay.add(Calendar.DATE, -1);
            String yesterday = df.format(calYesterDay.getTime());
            //查询节假日表是否有记录
            SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(yesterday);
            if(ObjectUtils.isEmpty(sysConfigHoliday)){
                //判断今天是否不是周末
                if (calYesterDay.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY || calYesterDay.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
                    //遍历在职员工向考勤记录添加数据
                    for (User user : userList) {
                        //用户钉钉id
                        List<String> userDinDingList = new ArrayList<>();
                        userDinDingList.add(user.getDingding());
                        //查询当前用户的排班
                        SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getRosteringId());
                        //查询考勤记录是否存在
                        Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), yesterday);
                        //访问钉钉获取数据
                        List<OapiDingTalkRecordResult> oapiDingTalkRecordResultList = new ArrayList<>();
                        oapiDingTalkRecordResultList = opaiDingTalkService.getAttendanceList(oapiDingTalkRecordResultList, oapiDingTalkAccessToken.getAccessToken(), yesterday + " 00:00:00", userDinDingList, 0l, 50l);
                        //判断钉钉是否获取数据
                        if (oapiDingTalkRecordResultList.size() != 0) {
                            for (OapiDingTalkRecordResult oapiDingTalkRecordResult : oapiDingTalkRecordResultList) {
                                if ("NotSigned".equals(oapiDingTalkRecordResult.getTimeResult())) {
                                    oapiDingTalkRecordResult.setUserCheckTime(null);
                                }
                                if ("OffDuty".equals(oapiDingTalkRecordResult.getCheckType())) {
                                    //判断状态
                                    String result = ObjectUtils.isEmpty(oapiDingTalkRecordResult.getUserCheckTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : Constant.ATTENDANCE_STATE_NORMAL;
                                    attendance.setEndClockResults(result);
                                    attendance.setEndLocationResults(setLocationResults(oapiDingTalkRecordResult.getLocationResult()));
                                    attendance.setActualWorkEndTime(oapiDingTalkRecordResult.getUserCheckTime());
                                }
                            }
                            attendanceRepository.save(attendance);
                            // 判断修改考勤状态
                            updateRecord(user,yesterday);
                        }
                    }
                }
            }
        }
    }
    /**
     * 判断返回位置状态
     * @param locationResults
     * @return
     */
    public String setLocationResults(String locationResults){
        String result = "";
        if(locationResults.equals("Normal")) {
            result = Constant.LOCATION_RESULTS_NORMAL;
        } else if(locationResults.equals("Outside")){
            result = Constant.LOCATION_RESULTS_OUTSIDE;
        } else if(locationResults.equals("NotSigned")){
            result = Constant.LOCATION_RESULTS_NOTSIGNED;
        }
        return result;
    }
    /**
     * 查询用户
     */
    public List<User> getUserList(){
        List<User> userList = userRepository.findAllByEnabled(true);
        return userList;
    }
    /**
     * 判断修改考勤状态
     * @param user
     * @param date
     */
    public void updateRecord(User user, String date){
        //根据日期查询请假表
        //根据日期查询外出表
        //根据日期查询出差表
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/User.java
@@ -78,6 +78,12 @@
    @ApiModelProperty(value = "邮箱")
    private String email;
    @ApiModelProperty(value = "钉钉ID")
    private String dingding;
    @ApiModelProperty(value = "排班ID")
    private Long rosteringId;
    @NotBlank
    @ApiModelProperty(value = "电话号码")
    private String phone;
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java
@@ -127,4 +127,11 @@
    @Query(value = "SELECT count(1) FROM sys_user u, sys_users_roles r WHERE " +
            "u.user_id = r.user_id AND r.role_id in ?1", nativeQuery = true)
    int countByRoles(Set<Long> ids);
    /**
     * 根据状态查询
     * @param enabled
     * @return
     */
    List<User> findAllByEnabled(Boolean enabled);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java
@@ -102,6 +102,13 @@
        return new ResponseEntity<>(PageUtil.toPage(null,0),HttpStatus.OK);
    }
    @GetMapping(value = "/getUsers")
    @Log("查询在职的员工")
    @ApiOperation("查询在职的员工")
    public ResponseEntity<Object> getUsers() {
        return new ResponseEntity<>(userService.getUsers(), HttpStatus.OK);
    }
    @Log("新增用户")
    @ApiOperation("新增用户")
    @PostMapping
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/UserService.java
@@ -122,4 +122,10 @@
     * @param resources /
     */
    void updateCenter(User resources);
    /**
     * 查询在职的员工
     * @return
     */
    List<User> getUsers();
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java
@@ -47,6 +47,10 @@
    private String email;
    private String dingding;
    private Long rosteringId;
    private String phone;
    private String gender;
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -229,6 +229,16 @@
        flushCache(username);
    }
    /**
     * 查询在职员工
     * @return
     */
    @Override
    public List<User> getUsers() {
        List<User> List = userRepository.findAllByEnabled(true);
        return List;
    }
    @Override
    public void download(List<UserDto> queryAll, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
@@ -240,6 +250,8 @@
            map.put("部门", userDTO.getDept().getName());
            map.put("岗位", userDTO.getJobs().stream().map(JobSmallDto::getName).collect(Collectors.toList()));
            map.put("邮箱", userDTO.getEmail());
            map.put("钉钉ID", userDTO.getDingding());
            map.put("排班ID", userDTO.getRosteringId());
            map.put("状态", userDTO.getEnabled() ? "启用" : "禁用");
            map.put("手机号码", userDTO.getPhone());
            map.put("修改密码的时间", userDTO.getPwdResetTime());
eladmin-web-master/src/api/attendance/attendance.js
New file
@@ -0,0 +1,36 @@
import request from '@/utils/request'
export function getAll(params) {
  return request({
    url: 'api/attendance/all',
    method: 'get',
    params
  })
}
export function add(data) {
  return request({
    url: 'api/attendance',
    method: 'post',
    data
  })
}
export function del(ids) {
  return request({
    url: 'api/attendance/',
    method: 'delete',
    data: ids
  })
}
export function edit(data) {
  return request({
    url: 'api/attendance',
    method: 'put',
    data
  })
}
export default { add, edit, del }
eladmin-web-master/src/api/system/user.js
@@ -57,5 +57,12 @@
  })
}
export default { add, edit, del }
export function getUsers() {
  return request({
    url: 'api/users/getUsers',
    method: 'get'
  })
}
export default { add, edit, del, getUsers }
eladmin-web-master/src/utils/constant.js
@@ -42,6 +42,30 @@
// 日期类型: 节假日(串休)
export const DATE_TYPE_HOLIDAYS = 'date_type_holidays'
// 考勤状态
export const ATTENDANCE_STATE = 'attendance_state'
// 考勤状态: 等待
export const ATTENDANCE_STATE_WAITFOR = 'attendance_state_waitFor'
// 考勤状态: 正常
export const ATTENDANCE_STATE_NORMAL = 'attendance_state_normal'
// 考勤状态: 缺卡
export const ATTENDANCE_STATE_NOTSIGNED = 'attendance_state_notSigned'
// 考勤状态: 外出
export const ATTENDANCE_STATE_GOOUT = 'attendance_state_goOut'
// 考勤状态: 出差
export const ATTENDANCE_STATE_BUSINESS = 'attendance_state_business'
// 考勤状态: 请假
export const ATTENDANCE_STATE_LEAVE = 'attendance_state_leave'
// 考勤位置状态
export const LOCATION_RESULTS = 'location_results'
// 考勤位置状态: 等待
export const LOCATION_RESULTS_NORMAL = 'location_results_normal'
// 考勤位置状态: 正常
export const LOCATION_RESULTS_OUTSIDE = 'location_results_outside'
// 考勤位置状态: 缺卡
export const LOCATION_RESULTS_NOTSIGNED = 'location_results_notSigned'
export default {
  CONFIG_PROPORTION_BASIC_WAGE,
  CONFIG_PROPORTION_MERIT_WAGE,
@@ -63,5 +87,16 @@
  DATE_TYPE,
  DATE_TYPE_WEEKDAY,
  DATE_TYPE_LEGAL_HOLIDAYS,
  DATE_TYPE_HOLIDAYS
  DATE_TYPE_HOLIDAYS,
  ATTENDANCE_STATE,
  ATTENDANCE_STATE_WAITFOR,
  ATTENDANCE_STATE_NORMAL,
  ATTENDANCE_STATE_NOTSIGNED,
  ATTENDANCE_STATE_GOOUT,
  ATTENDANCE_STATE_BUSINESS,
  ATTENDANCE_STATE_LEAVE,
  LOCATION_RESULTS,
  LOCATION_RESULTS_NORMAL,
  LOCATION_RESULTS_OUTSIDE,
  LOCATION_RESULTS_NOTSIGNED
}
eladmin-web-master/src/views/attendance/attendance/index.vue
New file
@@ -0,0 +1,261 @@
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <el-select v-model="query.userId" filterable clearable placeholder="请选择员工" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in users"
            :key="item.id"
            :label="item.nickName"
            :value="item.id"
          />
        </el-select>
        <el-date-picker
          v-model="query.attendanceDate"
          clearable
          class="filter-item"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期"
        />
        <el-select v-model="query.startLocationResults" filterable clearable placeholder="请选择开始位置结果" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[lacationResules]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.startClockResults" filterable clearable placeholder="请选择开始打卡结果" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[attendanceState]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.endLocationResults" filterable clearable placeholder="请选择结束位置结果" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[lacationResules]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.endClockResults" filterable clearable placeholder="请选择结束打卡结果" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[attendanceState]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="考勤日期" prop="attendanceDate">
            <el-input v-model="form.attendanceDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="排班工作开始时间" prop="rosteringWorkStartTime">
            <el-input v-model="form.rosteringWorkStartTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="实际工作开始时间" prop="actualWorkStartTime">
            <el-input v-model="form.actualWorkStartTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="开始位置结果" prop="startLocationResults">
            <el-input v-model="form.startLocationResults" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="开始打卡结果" prop="startClockResults">
            <el-input v-model="form.startClockResults" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="排班工作结束时间" prop="rosteringWorkEndTime">
            <el-input v-model="form.rosteringWorkEndTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="实际工作结束时间" prop="actualWorkEndTime">
            <el-input v-model="form.actualWorkEndTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="结束位置结果" prop="endLocationResults">
            <el-input v-model="form.endLocationResults" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="结束打卡结果" prop="endClockResults">
            <el-input v-model="form.endClockResults" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="日期类型" prop="dateType">
            <el-input v-model="form.dateType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" type="textarea" rows="3" maxlength="1000" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="userName" label="员工" show-overflow-tooltip />
        <el-table-column prop="attendanceDate" label="考勤日期" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.attendanceDate) }}
          </template>
        </el-table-column>
        <el-table-column prop="rosteringWorkStartTime" min-width="150" label="排班工作开始时间" show-overflow-tooltip />
        <el-table-column prop="actualWorkStartTime" min-width="150" label="实际工作开始时间" show-overflow-tooltip />
        <el-table-column prop="startLocationResults" label="开始位置结果" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.startLocationResults === 'location_results_normal'" type="success">{{ dict.label[lacationResules][scope.row.startLocationResults] }}</el-tag>
            <el-tag v-if="scope.row.startLocationResults === 'location_results_outside'" type="warning">{{ dict.label[lacationResules][scope.row.startLocationResults] }}</el-tag>
            <el-tag v-if="scope.row.startLocationResults === 'location_results_notSigned'" type="danger">{{ dict.label[lacationResules][scope.row.startLocationResults] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="startClockResults" label="开始打卡结果" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.startClockResults === 'attendance_state_waitFor'" type="warning">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag>
            <el-tag v-if="scope.row.startClockResults === 'attendance_state_normal'" type="success">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag>
            <el-tag v-if="scope.row.startClockResults === 'attendance_state_notSigned'" type="danger">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag>
            <el-tag v-if="scope.row.startClockResults === 'attendance_state_goOut'" type="success">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag>
            <el-tag v-if="scope.row.startClockResults === 'attendance_state_business'" type="success">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag>
            <el-tag v-if="scope.row.startClockResults === 'attendance_state_leave'" type="success">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="rosteringWorkEndTime" min-width="150" label="排班工作结束时间" show-overflow-tooltip />
        <el-table-column prop="actualWorkEndTime" min-width="150" label="实际工作结束时间" show-overflow-tooltip />
        <el-table-column prop="endLocationResults" label="结束位置结果" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.endLocationResults === 'location_results_normal'" type="success">{{ dict.label[lacationResules][scope.row.endLocationResults] }}</el-tag>
            <el-tag v-if="scope.row.endLocationResults === 'location_results_outside'" type="warning">{{ dict.label[lacationResules][scope.row.endLocationResults] }}</el-tag>
            <el-tag v-if="scope.row.endLocationResults === 'location_results_notSigned'" type="danger">{{ dict.label[lacationResules][scope.row.endLocationResults] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="endClockResults" label="结束打卡结果" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.endClockResults === 'attendance_state_waitFor'" type="warning">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag>
            <el-tag v-if="scope.row.endClockResults === 'attendance_state_normal'" type="success">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag>
            <el-tag v-if="scope.row.endClockResults === 'attendance_state_notSigned'" type="danger">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag>
            <el-tag v-if="scope.row.endClockResults === 'attendance_state_goOut'" type="success">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag>
            <el-tag v-if="scope.row.endClockResults === 'attendance_state_business'" type="success">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag>
            <el-tag v-if="scope.row.endClockResults === 'attendance_state_leave'" type="success">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="dateType" label="日期类型" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ dict.label[dateType][scope.row.dateType] }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="150" show-overflow-tooltip />
        <el-table-column v-if="checkPer(['admin','attendance:edit','attendance:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
<script>
import crudAttendance from '@/api/attendance/attendance'
import { getUsers } from '@/api/system/user'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import constant from '@/utils/constant'
const defaultForm = { id: null, userId: null, attendanceDate: null, rosteringWorkStartTime: null, actualWorkStartTime: null, startLocationResults: null, startClockResults: null, rosteringWorkEndTime: null, actualWorkEndTime: null, endLocationResults: null, endClockResults: null, dateType: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'Attendance',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '考勤记录', url: 'api/attendance', idField: 'id', sort: 'id,desc', crudMethod: { ...crudAttendance }})
  },
  // 数据字典
  dicts: [constant.ATTENDANCE_STATE, constant.DATE_TYPE, constant.LOCATION_RESULTS],
  data() {
    return {
      permission: {
        add: ['admin', 'attendance:add'],
        edit: ['admin', 'attendance:edit'],
        del: ['admin', 'attendance:del'],
        download: ['admin', 'attendance:download']
      },
      rules: {
        userId: [
          { required: true, message: '用户ID 外键不能为空', trigger: 'blur' }
        ],
        attendanceDate: [
          { required: true, message: '考勤日期不能为空', trigger: 'blur' }
        ],
        rosteringWorkStartTime: [
          { required: true, message: '排班工作开始时间不能为空', trigger: 'blur' }
        ],
        actualWorkStartTime: [
          { required: true, message: '实际工作开始时间不能为空', trigger: 'blur' }
        ],
        startLocationResults: [
          { required: true, message: '开始位置结果不能为空', trigger: 'blur' }
        ],
        startClockResults: [
          { required: true, message: '开始打卡结果不能为空', trigger: 'blur' }
        ],
        rosteringWorkEndTime: [
          { required: true, message: '排班工作结束时间不能为空', trigger: 'blur' }
        ],
        actualWorkEndTime: [
          { required: true, message: '实际工作结束时间不能为空', trigger: 'blur' }
        ],
        endLocationResults: [
          { required: true, message: '结束位置结果不能为空', trigger: 'blur' }
        ],
        endClockResults: [
          { required: true, message: '结束打卡结果不能为空', trigger: 'blur' }
        ],
        dateType: [
          { required: true, message: '日期类型不能为空', trigger: 'blur' }
        ],
        createBy: [
          { required: true, message: '创建者不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ]
      },
      attendanceState: constant.ATTENDANCE_STATE,
      lacationResules: constant.LOCATION_RESULTS,
      dateType: constant.DATE_TYPE,
      users: [] }
  },
  created() {
    this.getUsers()
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    // 查询在职员工
    getUsers() {
      getUsers().then(res => {
        this.users = res
      })
    }
  }
}
</script>
<style scoped>
</style>