提交 d03fac88 authored 作者: gongwenjie's avatar gongwenjie

考勤

上级 fb38425e
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
/*
* Copyright 2007-present the original author or authors.
*
* 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
*
* https://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.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
差异被折叠。
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>tynotes</artifactId>
<groupId>com.zjty.tynotes</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-attendance</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>notes-attendance</name>
<description>Demo project for Spring Boot</description>
<dependencies>
<dependency>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-misc</artifactId>
<exclusions>
<exclusion>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-attendance</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-pas</artifactId>
<exclusions>
<exclusion>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-attendance</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-sms</artifactId>
<exclusions>
<exclusion>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-attendance</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-search</artifactId>
<exclusions>
<exclusion>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-attendance</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-redis</artifactId>
<exclusions>
<exclusion>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-attendance</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- 钉钉接口依赖调用 -->
<dependency>
<groupId>com.dingtalk</groupId>
<artifactId>2</artifactId>
<version>2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/taobao-sdk-java-auto_1479188381469-20200309-source.jar</systemPath>
</dependency>
<dependency>
<groupId>com.dingtalk</groupId>
<artifactId>3</artifactId>
<version>2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/taobao-sdk-java-auto_1479188381469-20200309.jar</systemPath>
</dependency>
</dependencies>
</project>
package com.zjty.tynotes.attendance;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class NotesAttendanceApplication {
public static void main(String[] args) {
SpringApplication.run(NotesAttendanceApplication.class, args);
}
}
package com.zjty.tynotes.attendance.controller;
import com.zjty.tynotes.attendance.entity.ApprovalInformation;
import com.zjty.tynotes.attendance.service.ApprovalInformationService;
import com.zjty.tynotes.misc.config.AutoDocument;
import com.zjty.tynotes.pas.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import static org.springframework.http.ResponseEntity.ok;
/**
* @Author gwj
* @create 2020/3/24 15:35
* 审批流程视图层
*/
@Api(tags = "考勤模块", protocols = "http")
@RestController
@RequestMapping("/attendance/approval")
@AutoDocument
public class ApprovalController {
private static final Logger logger = LoggerFactory.getLogger(ApprovalController.class);
@Autowired
private ApprovalInformationService approvalInformationService;
@ApiOperation(value = "提交审批", response = ApprovalInformation.class)
@PostMapping("/submit")
public ResponseEntity addUser(@RequestBody ApprovalInformation approvalInformation) {
ApprovalInformation approvalInformation1 = approvalInformationService.addApproval(approvalInformation);
if(approvalInformation1!=null){
return ok(approvalInformation1);
}
return ok("提交审批失败,是否可有加班时长");
}
@ApiOperation(value = "删除审批")
@DeleteMapping("/delete/{id}")
public ResponseEntity delete(@PathVariable("id") String id) {
try {
boolean b = approvalInformationService.deleteApproval(id);
if(b){
return ok("删除审批成功");
}
} catch (Exception e) {
logger.error("删除审批失败");
}
return ok("删除审批失败");
}
@ApiOperation(value = "审核审批")
@DeleteMapping("/audit/{userId}/{id}/{approvalStatus}")
public ResponseEntity audit(@PathVariable String userId,@PathVariable String id,@PathVariable String approvalStatus) {
try {
ApprovalInformation approvalInformation = approvalInformationService.auditApproval(userId,id,approvalStatus);
return ok(approvalInformation);
} catch (Exception e) {
logger.error("审核审批失败");
}
return ok("审核审批失败");
}
@ApiOperation(value = "查找所有我提交的审批")
@GetMapping("findAllSubmitApproval/{userId}")
public ResponseEntity findAllSubmitApproval(@PathVariable String userId) {
try {
List<ApprovalInformation> approvalInformations = approvalInformationService.findAllApproval(userId);
return ok(approvalInformations);
} catch (Exception e) {
logger.error("查找自身提交的审批失败");
}
return ok("查找自身提交的审批失败");
}
@ApiOperation(value = "查找所有我审核的审批")
@GetMapping("findAllAuditApproval/{userId}")
public ResponseEntity findAllAuditApproval(@PathVariable String userId) {
try {
List<ApprovalInformation> approvalInformations = approvalInformationService.findAllAuditApproval(userId);
return ok(approvalInformations);
} catch (Exception e) {
logger.error("查找所有我审核的审批");
}
return ok("查找所有我审核的审批");
}
}
package com.zjty.tynotes.attendance.controller;
import com.zjty.tynotes.attendance.entity.ApprovalInformation;
import com.zjty.tynotes.attendance.entity.vo.request.AttenRequest;
import com.zjty.tynotes.attendance.service.AttendanceDetailsService;
import com.zjty.tynotes.misc.config.AutoDocument;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import static org.springframework.http.ResponseEntity.ok;
/**
* @Author gwj
* @create 2020/3/25 9:12
* @des 考勤信息统计
*/
@Api(tags = "考勤模块", protocols = "http")
@RestController
@AutoDocument
@RequestMapping("/attendance/info")
public class AttendanceController {
@Autowired
private AttendanceDetailsService attendanceDetailsService;
@ApiOperation(value = "查询个人考勤信息", response = ApprovalInformation.class)
@PostMapping("/personnel")
public ResponseEntity personnel(@RequestBody AttenRequest request){
return ok(attendanceDetailsService.findPersonnel(request));
}
@ApiOperation(value = "查询部门考勤信息", response = ApprovalInformation.class)
@GetMapping("/department")
public ResponseEntity department(@RequestBody AttenRequest request){
return ok(attendanceDetailsService.findDepartment(request));
}
}
package com.zjty.tynotes.attendance.controller;
/**
* @Author gwj
* @create 2020/3/24 13:36
*/
import com.zjty.tynotes.attendance.service.DingUserService;
import com.zjty.tynotes.attendance.task.MyInit;
import com.zjty.tynotes.misc.config.AutoDocument;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import static org.springframework.http.ResponseEntity.ok;
/**
* @author mcj
*/
@Api(tags = "钉钉", protocols = "http")
@RestController
@RequestMapping("/attendance/user")
@AutoDocument
public class DingUserController {
private static final Logger logger = LoggerFactory.getLogger(DingUserController.class);
@Autowired
private DingUserService dingUserService;
@Autowired
private MyInit init;
@GetMapping("/getToken")
@ApiOperation(value = "手动获取钉钉token的接口")
public ResponseEntity getToken(){
try {
init.getToken();
return ok("重新获取token成功");
} catch (Exception e) {
logger.error("获取token失败");
}
return ok("重新获取token失败");
}
@GetMapping("/getDingUser")
@ApiOperation(value = "手动获取钉钉的用户与本地用户进行绑定")
public ResponseEntity getDingUser(){
try {
dingUserService.initDingUser();
return ok("用户绑定成功");
} catch (Exception e) {
logger.error("用户绑定失败");
}
return ok("用户绑定失败");
}
}
package com.zjty.tynotes.attendance.dao;
import com.zjty.tynotes.attendance.entity.ApprovalInformation;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/24 15:23
*/
public interface ApprovalInformationDao extends MongoRepository<ApprovalInformation,String> {
List<ApprovalInformation> findAllByUserId(String userId);
List<ApprovalInformation> findAllByApprovalUserIdOneOrApprovalUserIdTwo(String userId);
}
package com.zjty.tynotes.attendance.dao;
import com.zjty.tynotes.attendance.entity.AttendanceDepartment;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @Author gwj
* @create 2020/3/26 10:06
*/
public interface AttendanceDepartmentDao extends MongoRepository<AttendanceDepartment,String> {
}
package com.zjty.tynotes.attendance.dao;
import com.zjty.tynotes.attendance.entity.AttendanceDetails;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.Date;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/24 14:55
*/
public interface AttendanceDetailsDao extends MongoRepository<AttendanceDetails,String> {
AttendanceDetails findByUserId(String userId);
AttendanceDetails findByUserIdAndDate(String userId,Date date);
List<AttendanceDetails> findAllByUserIdAndDateBetween(String userId,Date startDate,Date endDate);
}
package com.zjty.tynotes.attendance.dao;
import com.zjty.tynotes.attendance.entity.CardResult;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @Author gwj
* @create 2020/3/24 14:51
*/
public interface CardResultDao extends MongoRepository<CardResult,String> {
}
package com.zjty.tynotes.attendance.dao;
import com.zjty.tynotes.attendance.entity.DingUser;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @Author gwj
* @create 2020/3/24 13:33
*/
public interface DingUserDao extends MongoRepository<DingUser,String> {
}
package com.zjty.tynotes.attendance.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;
/**
* @Author gwj
* @create 2020/3/24 15:03
* @des 审批信息表
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "审批信息", description = "审批信息")
@Document(collection = "ding_appro")
public class ApprovalInformation {
@Id
@ApiModelProperty(value = "id",example = "1")
private String id;
@ApiModelProperty(value = "提交审批用户id",example = "1")
private String userId;
@ApiModelProperty(value = "审核审批用户id",example = "1")
private String approvalUserIdOne;
@ApiModelProperty(value = "审核审批用户id",example = "1")
private String approvalUserIdTwo;
@ApiModelProperty(value = "审批类型",example = "事假/调休/病假/加班/公出")
private String approvalType;
@ApiModelProperty(value = "审批状态,0代表待审批,1代表已通过,2代表已拒绝",example = "0/1/2")
private String status;
@ApiModelProperty(value = "审批描述",example = "...")
private String description;
@ApiModelProperty(value = "审批不通过原因",example = "请假过多,不予请假")
private String reason;
@ApiModelProperty(value = "审批等级,一级审批还是二级审批",example = "1")
private String approvalLevel;
@ApiModelProperty(value = "请假开始时间",example = "2020-03-20 09:00:00")
private Date leaveStartTime;
@ApiModelProperty(value = "请假结束时间",example = "2020-03-21 09:00:00")
private Date leaveEndTime;
@ApiModelProperty(value = "一级审批是否通过",example = "0/1")
private String approvalOne;
@ApiModelProperty(value = "二级审批是否通过",example = "0/1")
private String approvalTwo;
@ApiModelProperty(value = "当前审批是否通过,0代表通过,1代表未通过",example = "0")
private String approvalStatus;
}
package com.zjty.tynotes.attendance.entity;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @Author gwj
* @create 2020/3/26 9:36
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "个人考勤信息", description = "个人考勤信息")
@Document(collection = "ding_attendepart")
public class AttendanceDepartment {
private String id;
private Double attendancePercent;
private Double absenteeismPercent;
private Double lateWorkPercent;
private String name;
private Integer lateTime;
}
package com.zjty.tynotes.attendance.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;
/**
* @Author gwj
* @create 2020/3/24 14:07
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "个人考勤信息", description = "个人考勤信息")
@Document(collection = "ding_attendance")
public class AttendanceDetails {
@Id
@ApiModelProperty(value = "id",example = "1")
String id;
@ApiModelProperty(value = "用户id",example = "eqweqw12312e")
String userId;
@ApiModelProperty(value = "平均工时",example = "176")
Integer averageWorkHours;
@ApiModelProperty(value = "应出勤天数",example = "22")
Integer attendanceDay;
@ApiModelProperty(value = "实际出勤天数",example = "22")
Integer realAttendanceDay;
@ApiModelProperty(value = "迟到天数",example = "1")
Integer lateDay;
@ApiModelProperty(value = "早退天数",example = "1")
Integer leaveEarlyDay;
@ApiModelProperty(value = "缺卡次数",example = "2")
Integer lessCard;
@ApiModelProperty(value = "旷工天数",example = "2")
Integer absenteeismDay;
@ApiModelProperty(value = "加班时长",example = "10")
Integer workOverHours;
@ApiModelProperty(value = "调休天数",example = "1")
Float paidLeaveDay;
@ApiModelProperty(value = "病假天数",example = "1")
Float sickLeaveDay;
@ApiModelProperty(value = "公出天数",example = "1")
Float outSideBusinessDay;
@ApiModelProperty(value = "时间,只需要精确到月份",example = "2020-03")
Date date;
}
package com.zjty.tynotes.attendance.entity;
import com.dingtalk.api.response.OapiAttendanceListResponse;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;
/**
* @Author gwj
* @create 2020/3/24 9:18
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "个人打卡信息", description = "个人打卡信息")
@Document(collection = "ding_card")
public class CardResult {
@Id
@ApiModelProperty(value = "id",example = "1")
private String id;
@ApiModelProperty(value = "钉钉打卡信息的id",example = "123qdsdd212")
private Long dingCardId;
@ApiModelProperty(value = "考勤类型",example = "上班、下班")
private String checkType;
@ApiModelProperty(value = "用户id",example = "1")
private String userId;
@ApiModelProperty(value = "时间结果",example = "Normal/Early/Late/Absenteeism/..")
private String timeResult;
@ApiModelProperty(value = "关联的审批id,当该字段非空时,表示打卡记录与请假、加班等审批有关",example = "1")
private Integer approvId;
@ApiModelProperty(value = "实际打卡时间, 用户打卡时间的毫秒数",example = "2020-03-20 10:10:5")
private Date userCheckTime;
@ApiModelProperty(value = "位置结果",example = "范围内/范围外/未打卡")
private String locationResult;
public CardResult(OapiAttendanceListResponse.Recordresult recordresult) {
this.dingCardId = recordresult.getId();
this.checkType = recordresult.getCheckType();
this.timeResult = recordresult.getTimeResult();
this.userCheckTime = recordresult.getUserCheckTime();
this.locationResult = recordresult.getLocationResult();
}
}
package com.zjty.tynotes.attendance.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import javax.validation.constraints.NotEmpty;
/**
* @des 关联表,本地用户id与钉钉用户id关联
* @Author gwj
* @create 2020/3/24 9:21
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "用户关联", description = "用户关联")
@Document(collection = "ding_user")
public class DingUser {
@Id
@ApiModelProperty(value = "id",example = "1")
private String id;
@NotEmpty(message = "用户id")
@ApiModelProperty(value = "用户id",example = "eqsd12314rrqsad1233")
private String userId;
@NotEmpty(message = "钉钉用户id")
@ApiModelProperty(value = "钉钉用户id",example = "1111212112")
private String dingUserId;
}
package com.zjty.tynotes.attendance.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @Author gwj
* @create 2020/3/25 10:22
* @des 员工加班时长
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "员工加班时长", description = "员工加班时长")
@Document(collection = "ding_useroverwork")
public class UserOverWork {
@Id
@ApiModelProperty(value = "id",example = "1")
private String userId;
@ApiModelProperty(value = "加班时长",example = "2")
private Long overWorkHour;
}
package com.zjty.tynotes.attendance.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @Author gwj
* @create 2020/3/24 9:32
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "钉钉部门", description = "钉钉部门")
public class DingDepartment {
@ApiModelProperty(value = "部门id",example = "部门id")
private Integer id;
@ApiModelProperty(value = "部门名称",example = "部门名称")
private String name;
@ApiModelProperty(value = "父部门id,根部门为1",example = "父部门id,根部门为1")
private Integer parentid;
@ApiModelProperty(value = "是否同步创建一个关联此部门的企业群,true表示是,false表示不是",example = "是否同步创建一个关联此部门的企业群,true表示是,false表示不是")
private boolean createDeptGroup;
@ApiModelProperty(value = "当群已经创建后,是否有新人加入部门会自动加入该群, true表示是,false表示不是",example = "当群已经创建后,是否有新人加入部门会自动加入该群, true表示是,false表示不是")
private boolean autoAddUser;
@ApiModelProperty(value = "部门自定义字段",example = "部门自定义字段")
private String ext;
}
package com.zjty.tynotes.attendance.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/24 9:42
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class DingResponse<T> {
private Integer errcode;
private String errmsg;
private List<T> department;
}
package com.zjty.tynotes.attendance.entity.vo;
import com.zjty.tynotes.attendance.entity.AttendanceDetails;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author gwj
* @create 2020/3/25 10:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "返回前台的个人考勤统计信息", description = "返回前台的个人考勤统计信息")
public class UserAttenVo extends AttendanceDetails {
private String name;
}
package com.zjty.tynotes.attendance.entity.vo.request;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author gwj
* @create 2020/3/26 9:07
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "个人考勤统计请求类", description = "个人考勤统计请求类")
public class AttenRequest {
private String id;
private String date;
private String searchType;//0代表按月份查找,1代表按年份查找
}
package com.zjty.tynotes.attendance.service;
import com.zjty.tynotes.attendance.entity.ApprovalInformation;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/24 15:23
* @des 提交审批业务处理
*/
public interface ApprovalInformationService {
/**
* 提交审批
* @param approvalInformation
* @return
*/
ApprovalInformation addApproval(ApprovalInformation approvalInformation);
/**
* 删除审批
* @param id
*/
boolean deleteApproval(String id);
/**
* 审核审批
* @param id
* @param status
* @return
*/
ApprovalInformation auditApproval(String userId,String id, String status);
/**
* 查询所有用户自身提交的审批
* @param userId
* @return
*/
List<ApprovalInformation> findAllApproval(String userId);
List<ApprovalInformation> findAllAuditApproval(String userId);
}
package com.zjty.tynotes.attendance.service;
import com.zjty.tynotes.attendance.entity.vo.UserAttenVo;
import com.zjty.tynotes.attendance.entity.vo.request.AttenRequest;
/**
* @Author gwj
* @create 2020/3/24 14:56
*/
public interface AttendanceDetailsService {
UserAttenVo findPersonnel(AttenRequest id);
Object findDepartment(AttenRequest request);
}
package com.zjty.tynotes.attendance.service;
/**
* @Author gwj
* @create 2020/3/24 14:53
*/
public interface CardResultService {
}
package com.zjty.tynotes.attendance.service;
/**
* @Author gwj
* @create 2020/3/24 13:47
*/
public interface DingUserService {
void initDingUser();
}
package com.zjty.tynotes.attendance.service.impl;
import com.zjty.tynotes.attendance.dao.ApprovalInformationDao;
import com.zjty.tynotes.attendance.dao.AttendanceDetailsDao;
import com.zjty.tynotes.attendance.entity.ApprovalInformation;
import com.zjty.tynotes.attendance.entity.AttendanceDetails;
import com.zjty.tynotes.attendance.service.ApprovalInformationService;
import com.zjty.tynotes.pas.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
* @Author gwj
* @create 2020/3/24 15:23
*/
@Service
public class ApprovalInformationServiceImpl implements ApprovalInformationService {
@Autowired
private ApprovalInformationDao approvalInformationDao;
@Autowired
private AttendanceDetailsDao attendanceDetailsDao;
@Autowired
private IUserService iUserService;
@Override
public ApprovalInformation addApproval(ApprovalInformation approvalInformation) {
if(approvalInformation.getApprovalType().equals("调休")){
String userId = approvalInformation.getUserId();
AttendanceDetails attendanceDetails = attendanceDetailsDao.findByUserId(userId);
Integer workOverHours = attendanceDetails.getWorkOverHours();
Date leaveEndTime = approvalInformation.getLeaveEndTime();
Date leaveStartTime = approvalInformation.getLeaveStartTime();
long l = leaveEndTime.getTime() - leaveStartTime.getTime();
long daytime = 24*60*60*1000;
long day;
if(l%daytime==0){
day = l/daytime;
}else{
day = l/daytime + 1;
}
if(workOverHours<=(day*8)){
return null;
}
if(day>2){
approvalInformation.setApprovalLevel("1");
}else{
approvalInformation.setApprovalLevel("2");
}
}
approvalInformation.setStatus("待审批");
return approvalInformationDao.save(approvalInformation);
}
@Override
public boolean deleteApproval(String id) {
Optional<ApprovalInformation> optional = approvalInformationDao.findById(id);
if(optional.isPresent()){
ApprovalInformation approvalInformation = optional.get();
String status = approvalInformation.getStatus();
if(("0").equals(status)){
approvalInformationDao.deleteById(id);
return true;
}
}
return false;
}
@Override
@Transactional
public ApprovalInformation auditApproval(String userId,String id, String approvalStatus) {
Optional<ApprovalInformation> optional = approvalInformationDao.findById(id);
ApprovalInformation approvalInformation = null;
if(optional.isPresent()){
approvalInformation = optional.get();
List<String> departmentLevels = iUserService.getDepartmentLevel(approvalInformation.getUserId(), userId);
if(departmentLevels.contains("2")||departmentLevels.contains("1")){
approvalInformation.setApprovalStatus(approvalStatus);
if(approvalStatus.equals("0")){
approvalInformation.setApprovalUserIdOne(userId);
approvalInformation.setStatus("1");
approvalInformation.setApprovalOne("0");
}else{
approvalInformation.setApprovalUserIdOne(userId);
approvalInformation.setStatus("2");
approvalInformation.setApprovalOne("1");
}
}else if(departmentLevels.contains("3")){
if(approvalStatus.equals("0")){
approvalInformation.setApprovalUserIdTwo(userId);
approvalInformation.setApprovalTwo("0");
}else{
approvalInformation.setApprovalUserIdTwo(userId);
approvalInformation.setStatus("1");
approvalInformation.setApprovalTwo("1");
}
}
}
return approvalInformation;
}
@Override
public List<ApprovalInformation> findAllApproval(String userId) {
return approvalInformationDao.findAllByUserId(userId);
}
@Override
public List<ApprovalInformation> findAllAuditApproval(String userId) {
return approvalInformationDao.findAllByApprovalUserIdOneOrApprovalUserIdTwo(userId);
}
}
package com.zjty.tynotes.attendance.service.impl;
import com.zjty.tynotes.attendance.dao.AttendanceDetailsDao;
import com.zjty.tynotes.attendance.entity.AttendanceDetails;
import com.zjty.tynotes.attendance.entity.vo.UserAttenVo;
import com.zjty.tynotes.attendance.entity.vo.request.AttenRequest;
import com.zjty.tynotes.attendance.service.AttendanceDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/24 14:56
*/
@Service
public class AttendanceDetailsServiceImpl implements AttendanceDetailsService {
@Autowired
private AttendanceDetailsDao attendanceDetailsDao;
@Override
public UserAttenVo findPersonnel(AttenRequest request) {
UserAttenVo userAttenVo = new UserAttenVo();
SimpleDateFormat sdf = null;
String searchType = request.getSearchType();
if(("0").equals(searchType)){
sdf = new SimpleDateFormat("yyyy-MM");
String format = sdf.format(request.getDate());
try {
Date parse = sdf.parse(format);
AttendanceDetails attendanceDetails = attendanceDetailsDao.findByUserIdAndDate(request.getId(), parse);
userAttenVo = (UserAttenVo) attendanceDetails;
userAttenVo.setName("");
return userAttenVo;
} catch (ParseException e) {
e.printStackTrace();
}
}else{
sdf = new SimpleDateFormat("yyyy");
String format = sdf.format(request.getDate());
Date endDate = null;
try {
Date startDate = sdf.parse(format + "-01");
endDate = sdf.parse(format + "-12");
List<AttendanceDetails> attendanceDetails = attendanceDetailsDao.findAllByUserIdAndDateBetween(request.getId(), startDate, endDate);
userAttenVo.setUserId(request.getId());
int averageWorkHours = 0;
int attendanceDay = 0;
int realAttendanceDay = 0;
int lateDay = 0;
int leaveEarlyDay = 0;
int lessCard = 0;
int absenteeismDay = 0;
int workOverHours = 0;
float paidLeaveDay = 0;
float sickLeaveDay = 0;
float outSideBusinessDay = 0;
for (AttendanceDetails attendanceDetails1 : attendanceDetails) {
averageWorkHours += attendanceDetails1.getAverageWorkHours();
attendanceDay += attendanceDetails1.getAttendanceDay();
realAttendanceDay += attendanceDetails1.getRealAttendanceDay();
lateDay += attendanceDetails1.getLateDay();
leaveEarlyDay += attendanceDetails1.getLeaveEarlyDay();
lessCard += attendanceDetails1.getLessCard();
absenteeismDay += attendanceDetails1.getAbsenteeismDay();
workOverHours += attendanceDetails1.getWorkOverHours();
paidLeaveDay += attendanceDetails1.getPaidLeaveDay();
sickLeaveDay += attendanceDetails1.getSickLeaveDay();
outSideBusinessDay += attendanceDetails1.getOutSideBusinessDay();
}
userAttenVo.setAverageWorkHours(averageWorkHours);
userAttenVo.setAttendanceDay(attendanceDay);
userAttenVo.setRealAttendanceDay(realAttendanceDay);
userAttenVo.setLateDay(lateDay);
userAttenVo.setLeaveEarlyDay(leaveEarlyDay);
userAttenVo.setLessCard(lessCard);
userAttenVo.setAbsenteeismDay(absenteeismDay);
userAttenVo.setWorkOverHours(workOverHours);
userAttenVo.setPaidLeaveDay(paidLeaveDay);
userAttenVo.setSickLeaveDay(sickLeaveDay);
userAttenVo.setOutSideBusinessDay(outSideBusinessDay);
userAttenVo.setName("");
return userAttenVo;
} catch (ParseException e) {
e.printStackTrace();
}
}
return null;
}
@Override
public Object findDepartment(AttenRequest request) {
return null;
}
}
package com.zjty.tynotes.attendance.service.impl;
import com.zjty.tynotes.attendance.service.CardResultService;
import org.springframework.stereotype.Service;
/**
* @Author gwj
* @create 2020/3/24 14:53
*/
@Service
public class CardResultServiceImpl implements CardResultService {
}
package com.zjty.tynotes.attendance.service.impl;
import com.zjty.tynotes.attendance.dao.DingUserDao;
import com.zjty.tynotes.attendance.entity.DingUser;
import com.zjty.tynotes.attendance.service.DingUserService;
import com.zjty.tynotes.attendance.task.MyInit;
import com.zjty.tynotes.pas.dao.PasUserDao;
import com.zjty.tynotes.pas.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/24 13:48
*/
@Service
public class DingUserServiceImpl implements DingUserService {
@Autowired
private PasUserDao pasUserDao;
@Autowired
private DingUserDao dingUserDao;
@Autowired
private MyInit init;
/**
* 获取钉钉用户与本地用户的所有对应关系
*/
@Override
public void initDingUser(){
init.userIds.clear();
init.dingUserList.clear();
init.getUserList();
List<User> users = pasUserDao.findAll();
List<DingUser> dingUsers = dingUserDao.findAll();
for (String dingsuerId : init.userIds) {
init.getUserDetails(dingsuerId,users,dingUsers);
}
dingUserDao.saveAll(init.dingUserList);
}
}
package com.zjty.tynotes.attendance.task;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiAttendanceListRequest;
import com.dingtalk.api.response.OapiAttendanceListResponse;
import com.taobao.api.ApiException;
import com.zjty.tynotes.attendance.dao.DingUserDao;
import com.zjty.tynotes.attendance.entity.DingUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @Author gwj
* @create 2020/3/26 14:51
* @des 定时任务,定时获取打卡信息
*/
@Component
public class CardTask {
private static final Logger logger = LoggerFactory.getLogger(CardTask.class);
@Value("ding.userCardUrl")
private String userCardUrl;
@Autowired
private MyInit init;
@Autowired
private DingUserDao dingUserDao;
/**
* 定时任务,定时获取打卡信息
*/
@Scheduled(cron = "0 59 23 * * ? ")
public void getCardDetails(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE,-1);
// LocalDateTime.now().minusDays(1).atOffset(ZoneOffset.ofHours(8)).format(DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00"));
Date time = calendar.getTime();
String startTime = sdf2.format(time);
String endTime = sdf2.format(new Date());
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/attendance/list");
OapiAttendanceListRequest request = new OapiAttendanceListRequest();
List<DingUser> dingUsers = dingUserDao.findAll();
List<String> dingUserIds = new ArrayList<>();
if(dingUsers!=null){
dingUsers.forEach(dingUser -> {
dingUserIds.add(dingUser.getDingUserId());
});
}
request.setWorkDateFrom(startTime);
request.setWorkDateTo(endTime);
request.setUserIdList(dingUserIds);
request.setOffset(0L);
request.setLimit(1L);
try {
init.getToken();
OapiAttendanceListResponse response = client.execute(request,init.token);
if(response!=null){
List<OapiAttendanceListResponse.Recordresult> recordresult = response.getRecordresult();
}
} catch (ApiException e) {
logger.error("定时获取打卡信息失败");
}
}
}
package com.zjty.tynotes.attendance.task;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiDepartmentListRequest;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiUserGetDeptMemberRequest;
import com.dingtalk.api.request.OapiUserGetRequest;
import com.dingtalk.api.response.OapiDepartmentListResponse;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiUserGetDeptMemberResponse;
import com.dingtalk.api.response.OapiUserGetResponse;
import com.taobao.api.ApiException;
import com.zjty.tynotes.attendance.dao.DingUserDao;
import com.zjty.tynotes.attendance.entity.DingUser;
import com.zjty.tynotes.pas.dao.PasUserDao;
import com.zjty.tynotes.pas.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @Author gwj
* @create 2020/3/24 10:07
*/
@Component
public class MyInit implements CommandLineRunner {
private static final Logger logger = LoggerFactory.getLogger(MyInit.class);
@Value("${ding.tokenUrl}")
private String tokenUrl;
@Value("${ding.departmentListUrl}")
private String departmentListUrl;
@Value("${ding.departmentMenberUrl}")
private String departmentMenberUrl;
@Value("${ding.userDetailsUrl}")
private String userDetailsUrl;
@Autowired
private PasUserDao pasUserDao;
@Autowired
private DingUserDao dingUserDao;
public String token;
public List<Long> dingDepartmentIds = new ArrayList<>();
//从钉钉获取的所有人员的id
public List<String> userIds = new ArrayList<>();
//根据丁丁的人员名单与本地的人员名单作对比后需要绑定的人员
public List<DingUser> dingUserList = new ArrayList<>();
@Override
public void run(String... args) throws Exception {
// getToken();
// getDepartmentList();
// getUserList();
// List<User> users = pasUserDao.findAll();
// List<DingUser> dingUsers = dingUserDao.findAll();
// for (String dingsuerId : userIds) {
// getUserDetails(dingsuerId,users,dingUsers);
// }
// dingUserDao.saveAll(dingUserList);
}
/**
* 钉钉获取token接口
* @return
*/
public void getToken(){
DefaultDingTalkClient client = new DefaultDingTalkClient(tokenUrl);
OapiGettokenRequest request = new OapiGettokenRequest();
request.setAppkey("dingpzurwgv19x9uzpgd");
request.setAppsecret("PgRC88Q8ML4S_tabbg5Oxne2fE43eemrHE4mFutcFcnPur4jbs3HshN-cpJAkF7-");
request.setHttpMethod("GET");
try {
OapiGettokenResponse response = client.execute(request);
token = response.getAccessToken();
} catch (ApiException e) {
logger.error("获取钉钉token失败");
}
}
/**
* 获取部门列表
* @return
*/
public void getDepartmentList(){
DingTalkClient client = new DefaultDingTalkClient(departmentListUrl);
OapiDepartmentListRequest request = new OapiDepartmentListRequest();
request.setHttpMethod("GET");
try {
OapiDepartmentListResponse response = client.execute(request, token);
List<OapiDepartmentListResponse.Department> departments = response.getDepartment();
if(departments!=null){
for (OapiDepartmentListResponse.Department department : departments) {
dingDepartmentIds.add(department.getId());
}
}
} catch (ApiException e) {
logger.error("获取钉钉部门列表失败");
}
}
/**
* 获取用户列表
* @return
*/
public void getUserList(){
DingTalkClient client = new DefaultDingTalkClient(departmentMenberUrl);
OapiUserGetDeptMemberRequest req = new OapiUserGetDeptMemberRequest();
req.setHttpMethod("GET");
OapiUserGetDeptMemberResponse rsp = null;
for (Long l : dingDepartmentIds) {
req.setDeptId(""+l);
try {
rsp = client.execute(req,token);
if(rsp!=null){
List<String> userIdList = rsp.getUserIds();
userIdList.forEach(str-> {
if (!userIds.contains(str)) {
userIds.add(str);
}
});
}
} catch (ApiException e) {
logger.error("获取钉钉用户列表失败");
}
}
}
/**
* 获取用户详情
* @param userId
* @param users
* @param dingUsers
*/
public void getUserDetails(String userId, List<User> users,List<DingUser> dingUsers){
DingTalkClient client = new DefaultDingTalkClient(userDetailsUrl);
OapiUserGetRequest request = new OapiUserGetRequest();
request.setUserid(userId);
request.setHttpMethod("GET");
try {
List<String> dingsuerIds = new ArrayList<>();
if(dingUsers!=null){
for (DingUser dingUser : dingUsers) {
dingsuerIds.add(dingUser.getDingUserId());
}
}
OapiUserGetResponse user = client.execute(request, token);
if(user!=null){
if(!dingsuerIds.contains(user.getUserid())){
for (User user1 : users) {
if(user.getName().equals(user1.getUsername())){
dingUserList.add(new DingUser(null,user.getUserid(),user1.getId()));
}
}
}else{
DingUser dingUser2 = null;
if(dingUsers!=null){
for (DingUser dingUser : dingUsers) {
if(dingUser.getDingUserId().equals(user.getUserid())){
dingUser2 = dingUser;
}
}
}
for (User user1 : users) {
if(user.getName().equals(user1.getUsername())){
dingUser2.setDingUserId(user.getUserid());
dingUser2.setUserId(user1.getId());
dingUserList.add(dingUser2);
}
}
}
}
} catch (ApiException e) {
logger.error("获取钉钉用户详情信息失败");
}
}
/**
* 每过一个小时准时获取一次token,因为钉钉的token会过期
*/
@Scheduled(cron = "0 0 0/1 * * ? ")
public void setToken(){
getToken();
}
}
ding:
# 获取access_token
tokenUrl: https://oapi.dingtalk.com/gettoken
# 获取钉钉部门列表地址
departmentListUrl: https://oapi:dingtalk:com/department/list
# 获取部门用户userid列表
departmentMenberUrl: https://oapi.dingtalk.com/user/getDeptMember
# 获取用户详情
userDetailsUrl: https://oapi.dingtalk.com/user/get
# 获取打卡结果地址
userCardUrl: https://oapi.dingtalk.com/attendance/list
# 钉钉的appkey
appKey: dingpzurwgv19x9uzpgd
appSecret: PgRC88Q8ML4S_tabbg5Oxne2fE43eemrHE4mFutcFcnPur4jbs3HshN-cpJAkF7-
package com.zjty.tynotes.attendance;
//import org.junit.jupiter.api.Test;
//import org.springframework.boot.test.context.SpringBootTest;
//@SpringBootTest
class NotesAttendanceApplicationTests {
// @Test
// void contextLoads() {
// }
}
...@@ -57,7 +57,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -57,7 +57,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.cors().and() .cors().and()
.authorizeRequests() .authorizeRequests()
.antMatchers("/pas/user/addGuanLian").permitAll() .antMatchers("/pas/user/addGuanLian").permitAll()
.antMatchers("/pas/user").permitAll() .antMatchers(HttpMethod.GET,"/pas/user").permitAll()
.antMatchers("/pas/user/encryPas").permitAll() .antMatchers("/pas/user/encryPas").permitAll()
.antMatchers(HttpMethod.GET,"/pas/department").permitAll() .antMatchers(HttpMethod.GET,"/pas/department").permitAll()
.antMatchers("/pas/user/findUserList/**").permitAll() .antMatchers("/pas/user/findUserList/**").permitAll()
......
...@@ -15,4 +15,5 @@ public interface DepartmentDao extends MongoRepository<Department,String> { ...@@ -15,4 +15,5 @@ public interface DepartmentDao extends MongoRepository<Department,String> {
List<Department> findAllByParentId(String parentId); List<Department> findAllByParentId(String parentId);
List<Department> findAllByIdIn(List<String> departmentIds); List<Department> findAllByIdIn(List<String> departmentIds);
} }
...@@ -123,4 +123,13 @@ public interface IUserService { ...@@ -123,4 +123,13 @@ public interface IUserService {
* @return * @return
*/ */
Object deleteRoot(); Object deleteRoot();
/**
* 返回所有上级部门id
* @param executeUserId
* @param userId
* @return
*/
List<String> getDepartmentLevel(String executeUserId,String userId);
} }
...@@ -482,6 +482,82 @@ public class UserServiceImpl implements IUserService { ...@@ -482,6 +482,82 @@ public class UserServiceImpl implements IUserService {
} }
} }
/**
* 供考勤模块的审批流程使用的接口
* @param userId
* @return 返回部门等级
*/
@Override
public List<String> getDepartmentLevel(String executeUserId, String userId){
Optional<User> optionalUser = pasUserDao.findById(executeUserId);
User user = null;
if(!optionalUser.isPresent()) {
return null;
}
user = optionalUser.get();
List<String> departmentIds = user.getDepartmentIds();
//查询所有的上级部门id集合
List<String> parentDepartIds = findParentDepartIds(departmentIds, new ArrayList<>());
List<UserRole> userRoles = userRoleDao.findAllByUserId(userId);
List<String> roleIds = new ArrayList<>();
if(userRoles!=null){
userRoles.forEach(userRole -> roleIds.add(userRole.getRoleId()));
}
List<Role> roles = roleDao.findAllByIdIn(roleIds);
List<String> departmentLevels = new ArrayList<>();
if(roles!=null){
roles.forEach(role -> {
List<Authority> authorities = role.getAuthorities();
authorities.forEach(authority -> {
String name = authority.getName();
if(("审批权限".equals(name))){
String departmentId = role.getDepartmentId();
if(parentDepartIds.contains(departmentId)){
Optional<Department> optional = departmentDao.findById(departmentId);
Department department = null;
if(optional.isPresent()){
department = optional.get();
}
if(!departmentLevels.contains(department.getLevel())){
departmentLevels.add(department.getLevel());
}
}
}
});
});
}
return departmentLevels;
}
/**
* 查询所有上级部门
* @param departIds 需要传入的用户部门集合
* @param departmentIds 用来存所有上级部门id集合
* @return
*/
public List<String> findParentDepartIds(List<String> departIds,List<String> departmentIds){
List<String> ids = new ArrayList<>();
departIds.forEach(str->{
Department department = null;
Optional<Department> optional = departmentDao.findById(str);
if(optional.isPresent()){
department = optional.get();
if((!department.getLevel().equals("1"))&&(!department.getLevel().equals("2"))){
if(!departmentIds.contains(str)){
if(optional.isPresent()){
String parentId = department.getParentId();
ids.add(parentId);
}
}
}
}
departmentIds.add(str);
});
findParentDepartIds(ids,departmentIds);
return departmentIds;
}
} }
...@@ -73,6 +73,12 @@ ...@@ -73,6 +73,12 @@
<artifactId>notes-pas</artifactId> <artifactId>notes-pas</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.zjty.tynotes</groupId>
<artifactId>notes-attendance</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
......
...@@ -21,13 +21,14 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -21,13 +21,14 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
"com.zjty.tynotes.redis", "com.zjty.tynotes.redis",
"com.zjty.tynotes.weekly", "com.zjty.tynotes.weekly",
"com.zjty.tynotes.misc", "com.zjty.tynotes.misc",
"com.zjty.tynotes.union" "com.zjty.tynotes.union",
"com.zjty.tynotes.attendance"
}) })
public class UnionApplication { public class UnionApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(UnionApplication.class, args); SpringApplication.run(UnionApplication.class, args);
} }
//// 开始支持http // 开始支持http
@Bean @Bean
public ServletWebServerFactory servletContainer() { public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
...@@ -35,14 +36,14 @@ public class UnionApplication { ...@@ -35,14 +36,14 @@ public class UnionApplication {
return tomcat; return tomcat;
} }
private Connector createHTTPConnector() { private Connector createHTTPConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
//同时启用http(8080)、https(8443)两个端口 //同时启用http(8080)、https(8443)两个端口
connector.setScheme("http"); connector.setScheme("http");
connector.setSecure(false); connector.setSecure(false);
connector.setPort(8084); connector.setPort(8084);
connector.setRedirectPort(8289); connector.setRedirectPort(8289);
return connector; return connector;
} }
} }
spring.application.name=workbook spring.application.name=workbook
## https端口号. ## https端口号.
server.port=8289 server.port=8289
## 证书的路径. ## 证书的路径.
......
...@@ -237,12 +237,12 @@ public class UserManageServiceImpl implements UserManageService { ...@@ -237,12 +237,12 @@ public class UserManageServiceImpl implements UserManageService {
departmentIds.add(departmentId); departmentIds.add(departmentId);
} }
} }
List<String> departmentIdList = new ArrayList<>(); List<Department> departmentList = departmentDao.findAllByIdIn(departmentIds);
getDepartments(departmentList);
// getDepartments(departmentIdList,departmentIds);
// List<Department> departments = departmentDao.findAllByIdIn(departmentIdList);
getDepartments(departmentIdList,departmentIds); return departmentList;
List<Department> departments = departmentDao.findAllByIdIn(departmentIdList);
return departments;
} }
/** /**
...@@ -310,6 +310,16 @@ public class UserManageServiceImpl implements UserManageService { ...@@ -310,6 +310,16 @@ public class UserManageServiceImpl implements UserManageService {
return des; return des;
} }
/**
* 递归获得部门树
* @param departments
*/
public void getDepartments(List<Department> departments) {
for (Department department : departments) {
List<Department> departmentList = departmentDao.findAllByParentId(department.getId());
getDepartments(departmentList);
department.setDepartments(departmentList);
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论