12 files added
6 files modified
| | |
| | | <groupId>org.apache.httpcomponents</groupId>
|
| | | <artifactId>httpclient</artifactId>
|
| | | <version>4.5.14</version>
|
| | | <scope>test</scope>
|
| | | <scope>compile</scope>
|
| | | </dependency>
|
| | |
|
| | | <!-- JSON -->
|
| | |
| | | <artifactId>json</artifactId>
|
| | | <version>20200518</version>
|
| | | </dependency>
|
| | |
|
| | | <!-- 企业微信开发 -->
|
| | | <dependency>
|
| | | <groupId>com.github.binarywang</groupId>
|
| | | <artifactId>wx-java-cp-spring-boot-starter</artifactId>
|
| | | <version>4.7.2.B</version>
|
| | | </dependency>
|
| | | </dependencies>
|
| | |
|
| | | <!-- 打包 -->
|
| New file |
| | |
| | | /* |
| | | * 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 javax.persistence.*; |
| | | import javax.validation.constraints.*; |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.Table; |
| | | |
| | | import me.zhengjie.base.BaseEntity; |
| | | import java.sql.Timestamp; |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | | * @description / |
| | | * @author baolh |
| | | * @date 2025-03-12 |
| | | **/ |
| | | @Entity |
| | | @Data |
| | | @Table(name="new_attendance") |
| | | public class NewAttendance 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_lunch_start_time`",nullable = false) |
| | | @NotNull |
| | | @ApiModelProperty(value = "排班午休开始时间") |
| | | private Timestamp rosteringLunchStartTime; |
| | | |
| | | @Column(name = "`rostering_lunch_end_time`",nullable = false) |
| | | @NotNull |
| | | @ApiModelProperty(value = "排班午休结束时间") |
| | | private Timestamp rosteringLunchEndTime; |
| | | |
| | | @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; |
| | | |
| | | @Column(name = "`dept_id`") |
| | | @ApiModelProperty(value = "部门ID") |
| | | private Long deptId; |
| | | |
| | | public void copy(NewAttendance source){ |
| | | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.NewAttendance; |
| | | 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 baolh |
| | | * @date 2025-03-12 |
| | | **/ |
| | | public interface NewAttendanceRepository extends JpaRepository<NewAttendance, Long>, JpaSpecificationExecutor<NewAttendance> { |
| | | /** 根据用户和日期查询考勤记录对象 **/ |
| | | @Query(value = "SELECT * FROM new_attendance WHERE user_id = ? AND attendance_date = ? " , nativeQuery = true) |
| | | NewAttendance findAllByUserIdAndAttendanceDate(Long userId, String baseDate); |
| | | |
| | | // /** 根据员工姓名模糊查询 **/ |
| | | // @Query(value = "SELECT * FROM attendance WHERE " , nativeQuery = true) |
| | | // List<NewAttendanceDto> findByUserNameLike(String userName); |
| | | |
| | | /** 根据时间范围查询考勤记录 **/ |
| | | @Query(value = "SELECT * FROM new_attendance WHERE user_id = ?1 AND attendance_date <= ?3 AND attendance_date >= ?2", nativeQuery = true) |
| | | List<NewAttendance> findAllByUserAndDate(Long userId, String startDate, String endDate); |
| | | |
| | | /** 根据日期查询考勤表 **/ |
| | | @Query(value = "SELECT * FROM new_attendance a LEFT JOIN sys_user u ON u.user_id = a.user_id WHERE a.attendance_date LIKE ? AND u.enabled != 0 ORDER BY a.user_id, a.attendance_date", nativeQuery = true) |
| | | List<NewAttendance> findAllLikeDate(String baseDate); |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.NewAttendance; |
| | | import me.zhengjie.modules.attendance.service.NewAttendanceService; |
| | | import me.zhengjie.modules.attendance.service.dto.NewAttendanceQueryCriteria; |
| | | 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 javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | | * @author baolh |
| | | * @date 2025-03-12 |
| | | **/ |
| | | @RestController |
| | | @RequiredArgsConstructor |
| | | @Api(tags = "考勤记录管理(2503企微版)管理") |
| | | @RequestMapping("/api/newAttendance") |
| | | public class NewAttendanceController { |
| | | |
| | | private final NewAttendanceService newAttendanceService; |
| | | |
| | | @Log("导出数据") |
| | | @ApiOperation("导出数据") |
| | | @GetMapping(value = "/download") |
| | | @PreAuthorize("@el.check('newAttendance:list')") |
| | | public void exportNewAttendance(HttpServletResponse response, NewAttendanceQueryCriteria criteria) throws IOException { |
| | | newAttendanceService.download(newAttendanceService.queryAll(criteria), response); |
| | | } |
| | | |
| | | @GetMapping |
| | | @Log("查询考勤记录管理(2503企微版)") |
| | | @ApiOperation("查询考勤记录管理(2503企微版)") |
| | | @PreAuthorize("@el.check('newAttendance:list')") |
| | | public ResponseEntity<Object> queryNewAttendance(NewAttendanceQueryCriteria criteria, Pageable pageable){ |
| | | return new ResponseEntity<>(newAttendanceService.queryAll(criteria,pageable),HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping(value = "/all") |
| | | @Log("查询考勤记录管理(2503企微版)") |
| | | @ApiOperation("查询考勤记录管理(2503企微版)") |
| | | @PreAuthorize("@el.check('newAttendance:list')") |
| | | public ResponseEntity<Object> queryAttendance(NewAttendanceQueryCriteria criteria){ |
| | | return new ResponseEntity<>(newAttendanceService.queryAll(criteria),HttpStatus.OK); |
| | | } |
| | | |
| | | @PostMapping |
| | | @Log("新增考勤记录管理(2503企微版)") |
| | | @ApiOperation("新增考勤记录管理(2503企微版)") |
| | | @PreAuthorize("@el.check('newAttendance:add')") |
| | | public ResponseEntity<Object> createNewAttendance(@Validated @RequestBody NewAttendance resources){ |
| | | return new ResponseEntity<>(newAttendanceService.create(resources),HttpStatus.CREATED); |
| | | } |
| | | |
| | | @PutMapping |
| | | @Log("修改考勤记录管理(2503企微版)") |
| | | @ApiOperation("修改考勤记录管理(2503企微版)") |
| | | @PreAuthorize("@el.check('newAttendance:edit')") |
| | | public ResponseEntity<Object> updateNewAttendance(@Validated @RequestBody NewAttendance resources){ |
| | | newAttendanceService.update(resources); |
| | | return new ResponseEntity<>(HttpStatus.NO_CONTENT); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | @Log("删除考勤记录管理(2503企微版)") |
| | | @ApiOperation("删除考勤记录管理(2503企微版)") |
| | | @PreAuthorize("@el.check('newAttendance:del')") |
| | | public ResponseEntity<Object> deleteNewAttendance(@RequestBody Long[] ids) { |
| | | newAttendanceService.deleteAll(ids); |
| | | return new ResponseEntity<>(HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping(value = "/attendanceHours") |
| | | @Log("查询某月出勤小时数(2503企微版)") |
| | | @ApiOperation("查询某月出勤小时数(2503企微版)") |
| | | @PreAuthorize("@el.check('newAttendance:list')") |
| | | public ResponseEntity<Object> queryAttendanceHours(NewAttendanceQueryCriteria criteria) { |
| | | return new ResponseEntity<>(newAttendanceService.queryAttendanceHours(criteria),HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping(value = "/queryAttendanceHours") |
| | | @Log("查询某天出勤小时数(2503企微版)") |
| | | @ApiOperation("查询某天出勤小时数(2503企微版)") |
| | | @PreAuthorize("@el.check('newAttendance:list')") |
| | | public ResponseEntity<Object> queryAttendanceHours(Long userId, String date) { |
| | | return new ResponseEntity<>(newAttendanceService.queryAttendanceHours(userId, date),HttpStatus.OK); |
| | | } |
| | | |
| | | @PostMapping(value = "/getUserMakeUpCard") |
| | | @Log("补卡判断登录人(2503企微版)") |
| | | @ApiOperation("补卡判断登录人(2503企微版)") |
| | | public ResponseEntity<Object> getUserMakeUpCard(@Validated @RequestBody String userId){ |
| | | newAttendanceService.getUserMakeUpCard(userId); |
| | | return new ResponseEntity<>(HttpStatus.CREATED); |
| | | } |
| | | |
| | | @PostMapping(value = "/addAttendanceInfo") |
| | | @Log("考勤记录管理(2503企微版)补充") |
| | | @ApiOperation("考勤记录管理(2503企微版)补充") |
| | | public ResponseEntity<Object> addAttendanceInfo(@Validated @RequestBody NewAttendance attendance) throws Exception { |
| | | newAttendanceService.addAttendanceInfo(attendance); |
| | | return new ResponseEntity<>(HttpStatus.CREATED); |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.Calculate; |
| | | import me.zhengjie.modules.attendance.domain.NewAttendance; |
| | | import me.zhengjie.modules.attendance.service.dto.NewAttendanceDto; |
| | | import me.zhengjie.modules.attendance.service.dto.NewAttendanceQueryCriteria; |
| | | 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 baolh |
| | | * @date 2025-03-12 |
| | | **/ |
| | | public interface NewAttendanceService { |
| | | |
| | | /** |
| | | * 查询数据分页 |
| | | * @param criteria 条件 |
| | | * @param pageable 分页参数 |
| | | * @return Map<String,Object> |
| | | */ |
| | | Map<String,Object> queryAll(NewAttendanceQueryCriteria criteria, Pageable pageable); |
| | | |
| | | /** |
| | | * 查询所有数据不分页 |
| | | * @param criteria 条件参数 |
| | | * @return List<NewAttendanceDto> |
| | | */ |
| | | List<NewAttendanceDto> queryAll(NewAttendanceQueryCriteria criteria); |
| | | |
| | | /** |
| | | * 根据ID查询 |
| | | * @param id ID |
| | | * @return NewAttendanceDto |
| | | */ |
| | | NewAttendanceDto findById(Long id); |
| | | |
| | | /** |
| | | * 创建 |
| | | * @param resources / |
| | | * @return NewAttendanceDto |
| | | */ |
| | | NewAttendanceDto create(NewAttendance resources); |
| | | |
| | | /** |
| | | * 编辑 |
| | | * @param resources / |
| | | */ |
| | | void update(NewAttendance resources); |
| | | |
| | | /** |
| | | * 计算时长(小时) |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | Integer calculateTimes(Calculate calculate, Long userId); |
| | | |
| | | /** |
| | | * 计算时长(天) |
| | | * |
| | | * @return |
| | | */ |
| | | Integer calculateDays(Calculate calculate); |
| | | |
| | | /** |
| | | * 多选删除 |
| | | * @param ids / |
| | | */ |
| | | void deleteAll(Long[] ids); |
| | | |
| | | /** |
| | | * 导出数据 |
| | | * @param all 待导出的数据 |
| | | * @param response / |
| | | * @throws IOException / |
| | | */ |
| | | void download(List<NewAttendanceDto> all, HttpServletResponse response) throws IOException; |
| | | |
| | | Double queryAttendanceHours(Long userId, String date); |
| | | |
| | | /** |
| | | * 查询某月出勤小时数 |
| | | * @param criteria 条件参数 |
| | | * @return List<AttendanceDto> |
| | | */ |
| | | Double queryAttendanceHours(NewAttendanceQueryCriteria criteria); |
| | | |
| | | Double queryAttendanceHolidaysOverTimeHours(NewAttendanceQueryCriteria criteria); |
| | | |
| | | /** |
| | | * 查询某月平日加班小时数 |
| | | * @param criteria 条件参数 |
| | | * @return List<AttendanceDto> |
| | | */ |
| | | Double queryAttendanceOverTimeHours(NewAttendanceQueryCriteria criteria); |
| | | |
| | | |
| | | void getUserMakeUpCard(String userId); |
| | | |
| | | /** |
| | | * 补充考勤信息 |
| | | * @param attendance |
| | | */ |
| | | void addAttendanceInfo(NewAttendance attendance) throws Exception; |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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 baolh |
| | | * @date 2025-03-12 |
| | | **/ |
| | | @Data |
| | | public class NewAttendanceDto 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 rosteringLunchStartTime; |
| | | |
| | | /** 排班午休结束时间 */ |
| | | private Timestamp rosteringLunchEndTime; |
| | | |
| | | /** 排班工作结束时间 */ |
| | | private Timestamp rosteringWorkEndTime; |
| | | |
| | | /** 实际工作结束时间 */ |
| | | private Timestamp actualWorkEndTime; |
| | | |
| | | /** 结束位置结果 */ |
| | | private String endLocationResults; |
| | | |
| | | /** 结束打卡结果 */ |
| | | private String endClockResults; |
| | | |
| | | /** 日期类型 */ |
| | | private String dateType; |
| | | |
| | | /** 备注 */ |
| | | private String remarks; |
| | | |
| | | /** 员工姓名 */ |
| | | private String userName; |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.util.List; |
| | | import me.zhengjie.annotation.Query; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | | * @author baolh |
| | | * @date 2025-03-12 |
| | | **/ |
| | | @Data |
| | | public class NewAttendanceQueryCriteria { |
| | | |
| | | /** 精确查询姓名 */ |
| | | @Query |
| | | private Long userId; |
| | | |
| | | /** 时间区间查询 */ |
| | | @Query(type = Query.Type.BETWEEN, propName = "attendanceDate") |
| | | private List<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; |
| | | |
| | | /* 模糊 */ |
| | | @Query(propName = "attendanceDate", type = Query.Type.INNER_LIKE) |
| | | private String attendanceDateLike; |
| | | |
| | | private String targetYearMonth; |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | import me.zhengjie.modules.attendance.repository.*; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl; |
| | | import me.zhengjie.modules.system.domain.Role; |
| | | 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.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.dto.SysConfigHolidayQueryCriteria; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.attendance.service.NewAttendanceService; |
| | | import me.zhengjie.modules.attendance.service.dto.NewAttendanceDto; |
| | | import me.zhengjie.modules.attendance.service.dto.NewAttendanceQueryCriteria; |
| | | import me.zhengjie.modules.attendance.service.mapstruct.NewAttendanceMapper; |
| | | 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 java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.*; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * @author baolh |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @date 2025-03-12 |
| | | **/ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class NewAttendanceServiceImpl implements NewAttendanceService { |
| | | |
| | | private final NewAttendanceRepository newAttendanceRepository; |
| | | private final NewAttendanceMapper newAttendanceMapper; |
| | | private final UserRepository userRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final AttendanceLeaveRepository attendanceLeaveRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | private final AttendanceOvertimeRepository attendanceOvertimeRepository; |
| | | private final WeComServiceImpl weComService; |
| | | |
| | | @Override |
| | | public Map<String, Object> queryAll(NewAttendanceQueryCriteria criteria, Pageable pageable) { |
| | | Page<NewAttendance> page = newAttendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); |
| | | //将实体转换为Dto(重写) |
| | | Function<NewAttendance, NewAttendanceDto> func = new Function<NewAttendance, NewAttendanceDto>() { |
| | | @Override |
| | | public NewAttendanceDto apply(NewAttendance attendance) { |
| | | // 将实体类转换成DTO |
| | | NewAttendanceDto attendanceDto = newAttendanceMapper.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<NewAttendanceDto> queryAll(NewAttendanceQueryCriteria criteria) { |
| | | return newAttendanceMapper.toDto(newAttendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public NewAttendanceDto findById(Long id) { |
| | | NewAttendance newAttendance = newAttendanceRepository.findById(id).orElseGet(NewAttendance::new); |
| | | ValidationUtil.isNull(newAttendance.getId(), "NewAttendance", "id", id); |
| | | return newAttendanceMapper.toDto(newAttendance); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public NewAttendanceDto create(NewAttendance resources) { |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | // 查询用户 |
| | | User user = userRepository.findById(resources.getUserId()).orElseGet(User::new); |
| | | resources.setRosteringLunchStartTime(Timestamp.valueOf(df.format(resources.getAttendanceDate()) + " " + dateTimeFormatter.format(user.getSysRostering().getLunchStartTime()))); |
| | | resources.setRosteringLunchEndTime(Timestamp.valueOf(df.format(resources.getAttendanceDate()) + " " + dateTimeFormatter.format(user.getSysRostering().getLunchEndTime()))); |
| | | return newAttendanceMapper.toDto(newAttendanceRepository.save(resources)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(NewAttendance resources) { |
| | | NewAttendance newAttendance = newAttendanceRepository.findById(resources.getId()).orElseGet(NewAttendance::new); |
| | | ValidationUtil.isNull(newAttendance.getId(), "NewAttendance", "id", resources.getId()); |
| | | newAttendance.copy(resources); |
| | | //获取当前登入人信息 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Role role = user.getRoles().iterator().next(); |
| | | //除超管、总经理只能修改自己信息 |
| | | if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) { |
| | | if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())) { |
| | | throw new BadRequestException("只能修改自己的记录"); |
| | | } |
| | | } |
| | | newAttendanceRepository.save(newAttendance); |
| | | } |
| | | |
| | | /** |
| | | * 计算时间(小时) |
| | | * |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer calculateTimes(Calculate calculate, Long userId) { |
| | | User userInfo = userRepository.getOne(userId); |
| | | SysRostering sysRostering = userInfo.getSysRostering(); |
| | | //计算天数 |
| | | Integer count = calculateDays(calculate); |
| | | Calculate startCalculate = new Calculate(); |
| | | startCalculate.setStart(calculate.getStart()); |
| | | startCalculate.setEnd(calculate.getStart()); |
| | | Integer startDays = calculateDays(startCalculate); |
| | | |
| | | Calculate endCalculate = new Calculate(); |
| | | endCalculate.setStart(calculate.getEnd()); |
| | | endCalculate.setEnd(calculate.getEnd()); |
| | | Integer endDays = calculateDays(endCalculate); |
| | | |
| | | Integer time = 0; |
| | | time = (count - startDays - endDays) * 8 * 3600; |
| | | calculate.setStart(formateDateTime(calculate.getStart(), sysRostering)); |
| | | calculate.setEnd(formateDateTime(calculate.getEnd(), sysRostering)); |
| | | |
| | | if (startDays > 0) { |
| | | Duration startDuration = Duration.between(calculate.getStart(), calculate.getStart().toLocalDate().atTime(sysRostering.getWorkEndTime())); |
| | | Long StartSeconds = startDuration.getSeconds(); |
| | | if (calculate.getStart().toLocalTime().isBefore(LocalTime.NOON)) { |
| | | time += StartSeconds.intValue() - 3600; |
| | | } else if (calculate.getStart().toLocalTime().compareTo(LocalTime.NOON) >= 0 && calculate.getStart().toLocalTime().compareTo(calculate.getStart().toLocalDate().atTime(sysRostering.getLunchEndTime()).toLocalTime()) < 0) { |
| | | //补充,请假开始时间大于等于中午基准休息时间小于休息结束时间 |
| | | time += StartSeconds.intValue() - 3600; |
| | | } else { |
| | | time += StartSeconds.intValue(); |
| | | } |
| | | } |
| | | if (endDays > 0) { |
| | | Duration endDuration = Duration.between(calculate.getEnd().toLocalDate().atTime(sysRostering.getWorkStartTime()), calculate.getEnd()); |
| | | Long endSeconds = endDuration.getSeconds(); |
| | | if (calculate.getEnd().toLocalTime().isAfter(LocalTime.NOON)) { |
| | | time += endSeconds.intValue() - 3600; |
| | | } else { |
| | | time += endSeconds.intValue(); |
| | | } |
| | | } |
| | | return time; |
| | | } |
| | | |
| | | /** |
| | | * 计算时间(天) |
| | | * |
| | | * @param calculate |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer calculateDays(Calculate calculate) { |
| | | List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>(); |
| | | //查询节假日表 |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll(); |
| | | for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayList) { |
| | | if (sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)) { |
| | | //工作日 |
| | | isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0, 10)); |
| | | } else { |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0, 10)); |
| | | } |
| | | } |
| | | Long chronoUnit = ChronoUnit.DAYS.between(calculate.getStart().toLocalDate(), calculate.getEnd().toLocalDate()); |
| | | Integer count = 0; |
| | | for (Integer i = 0; i <= chronoUnit; i++) { |
| | | LocalDate date = calculate.getStart().toLocalDate().plusDays(i); |
| | | Boolean isWeekend = date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | if ((!isWeekend && !holiday.contains(date.toString())) || (isWeekend && isWork.contains(date.toString()))) { |
| | | count++; |
| | | } |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | public LocalDateTime formateDateTime(LocalDateTime localDateTime, SysRostering sysRostering) { |
| | | if (localDateTime.toLocalTime().isBefore(sysRostering.getWorkStartTime())) { |
| | | return localDateTime.toLocalDate().atTime(sysRostering.getWorkStartTime()); |
| | | } else if (localDateTime.toLocalTime().isAfter(sysRostering.getLunchStartTime()) && localDateTime.toLocalTime().isBefore(sysRostering.getLunchEndTime())) { |
| | | return localDateTime.toLocalDate().atTime(sysRostering.getLunchEndTime()); |
| | | } else if (localDateTime.toLocalTime().isAfter(sysRostering.getWorkEndTime())) { |
| | | return localDateTime.toLocalDate().atTime(sysRostering.getWorkEndTime()); |
| | | } |
| | | return localDateTime; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteAll(Long[] ids) { |
| | | for (Long id : ids) { |
| | | //获取当前登入人信息 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Role role = user.getRoles().iterator().next(); |
| | | //根据id查询记录 |
| | | Optional<NewAttendance> attendance = newAttendanceRepository.findById(id); |
| | | //除超管、总经理只能删除自己信息 |
| | | if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) { |
| | | if (!Long.valueOf(attendance.get().getUserId()).equals(SecurityUtils.getCurrentUserId())) { |
| | | throw new BadRequestException("只能删除自己的记录"); |
| | | } |
| | | } |
| | | |
| | | newAttendanceRepository.deleteById(id); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 补卡判断登录人 |
| | | */ |
| | | @Override |
| | | public void getUserMakeUpCard(String userId) { |
| | | //获取当前登入人信息 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Role role = user.getRoles().iterator().next(); |
| | | //除超管、总经理只能补自己的卡 |
| | | if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) { |
| | | if (!Long.valueOf(userId).equals(SecurityUtils.getCurrentUserId())) { |
| | | throw new BadRequestException("只能补自己的卡"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 补充考勤信息 |
| | | * |
| | | * @param attendance |
| | | */ |
| | | @Override |
| | | public void addAttendanceInfo(NewAttendance attendance) throws Exception { |
| | | // 获取今天日期 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String todayDate = sdf.format(new Date()); |
| | | if (attendance.getAttendanceDate().compareTo(Timestamp.valueOf(todayDate)) >= 0) { |
| | | throw new BadRequestException("只能更新小于等于今天的考勤信息"); |
| | | } |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String attendanceDate = df.format(attendance.getAttendanceDate()); |
| | | List<User> userList = new ArrayList<>(); |
| | | if (ObjectUtils.isNotEmpty(attendance.getUserId())) { |
| | | User user = userRepository.findById(attendance.getUserId()).orElseGet(User::new); |
| | | userList.add(user); |
| | | } |
| | | // 调用0时定时任务 |
| | | weComService.getWeComAttendanceList(attendance.getAttendanceDate(), userList); |
| | | // 选择日期和员工更新员工的考勤信息,未选择员工则更新所有人 |
| | | weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate, userList); |
| | | } |
| | | |
| | | @Override |
| | | public void download(List<NewAttendanceDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (NewAttendanceDto newAttendance : all) { |
| | | String startLocationResults = newAttendance.getStartLocationResults() != null ? dictDetailRepository.findByDictNameAndValue("location_results", newAttendance.getStartLocationResults()).getLabel() : ""; |
| | | String startClockResults = newAttendance.getStartClockResults() != null ? dictDetailRepository.findByDictNameAndValue("attendance_state", newAttendance.getStartClockResults()).getLabel() : ""; |
| | | String endLocationResults = newAttendance.getEndLocationResults() != null ? dictDetailRepository.findByDictNameAndValue("location_results", newAttendance.getEndLocationResults()).getLabel() : ""; |
| | | String endClockResults = newAttendance.getEndClockResults() != null ? dictDetailRepository.findByDictNameAndValue("attendance_state", newAttendance.getEndClockResults()).getLabel() : ""; |
| | | String dateType = newAttendance.getDateType() != null ? dictDetailRepository.findByDictNameAndValue("date_type", newAttendance.getDateType()).getLabel() : ""; |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("员工", newAttendance.getUserName()); |
| | | map.put("考勤日期", newAttendance.getAttendanceDate()); |
| | | map.put("排班工作开始时间", newAttendance.getRosteringWorkStartTime()); |
| | | map.put("实际工作开始时间", newAttendance.getActualWorkStartTime()); |
| | | map.put("开始位置结果", startLocationResults); |
| | | map.put("开始打卡结果", startClockResults); |
| | | map.put("排班工作结束时间", newAttendance.getRosteringWorkEndTime()); |
| | | map.put("实际工作结束时间", newAttendance.getActualWorkEndTime()); |
| | | map.put("结束位置结果", endLocationResults); |
| | | map.put("结束打卡结果", endClockResults); |
| | | map.put("日期类型", dateType); |
| | | map.put("备注", newAttendance.getRemarks()); |
| | | map.put("创建者", newAttendance.getCreateBy()); |
| | | map.put("创建时间", newAttendance.getCreateTime()); |
| | | map.put("更新者", newAttendance.getUpdateBy()); |
| | | map.put("更新时间", newAttendance.getUpdateTime()); |
| | | list.add(map); |
| | | } |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | @Override |
| | | public Double queryAttendanceHours(Long userId, String date) { |
| | | NewAttendance attendanceDate = newAttendanceRepository.findAllByUserIdAndAttendanceDate(userId, date); |
| | | List<Calculate> resultParts = new ArrayList<>(); |
| | | |
| | | LocalDate localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime startOfDate = localDate.atTime(0, 0, 0); |
| | | LocalDateTime endOfDate = localDate.atTime(23, 59, 59); |
| | | |
| | | LocalDateTime actualWorkStartTime = attendanceDate.getActualWorkStartTime() == null ? null : attendanceDate.getActualWorkStartTime().toLocalDateTime(); |
| | | LocalDateTime actualWorkEndTime = attendanceDate.getActualWorkEndTime() == null ? null : attendanceDate.getActualWorkEndTime().toLocalDateTime(); |
| | | LocalDateTime rosteringWorkStartTime = attendanceDate.getRosteringWorkStartTime() == null ? null : attendanceDate.getRosteringWorkStartTime().toLocalDateTime(); |
| | | LocalDateTime rosteringLunchStartTime = attendanceDate.getRosteringLunchStartTime() == null ? null : attendanceDate.getRosteringLunchStartTime().toLocalDateTime(); |
| | | LocalDateTime rosteringLunchEndTime = attendanceDate.getRosteringLunchEndTime() == null ? null : attendanceDate.getRosteringLunchEndTime().toLocalDateTime(); |
| | | LocalDateTime rosteringWorkEndTime = attendanceDate.getRosteringWorkEndTime() == null ? null : attendanceDate.getRosteringWorkEndTime().toLocalDateTime(); |
| | | |
| | | // 出差信息(出差时无打卡信息,用出差信息补充) |
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(userId, startOfDate, endOfDate); |
| | | if (attendanceBusinessTravel != null) { |
| | | actualWorkStartTime = rosteringWorkStartTime; |
| | | actualWorkEndTime = rosteringWorkEndTime; |
| | | } |
| | | |
| | | if (actualWorkStartTime != null && actualWorkStartTime.isBefore(rosteringWorkStartTime)) { |
| | | actualWorkStartTime = rosteringWorkStartTime; |
| | | } |
| | | // if (actualWorkEndTime != null && actualWorkEndTime.isAfter(rosteringWorkEndTime)) { |
| | | // actualWorkEndTime = rosteringWorkEndTime; |
| | | // } |
| | | |
| | | List<Calculate> attendanceParts = new ArrayList<>(); |
| | | // 当日打卡信息不全不算 |
| | | if (actualWorkStartTime != null && actualWorkEndTime != null) { |
| | | attendanceParts.add(new Calculate(actualWorkStartTime, actualWorkEndTime)); |
| | | } |
| | | |
| | | // 休息时间管理 |
| | | List<Calculate> breakParts = new ArrayList<>(); |
| | | breakParts.add(new Calculate(rosteringLunchStartTime, rosteringLunchEndTime)); |
| | | |
| | | // 外出信息 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId, startOfDate, endOfDate); |
| | | attendanceParts.addAll( |
| | | attendanceGoOutList.stream().map(attendanceGoOut -> |
| | | new Calculate(attendanceGoOut.getOutStartTime().toLocalDateTime(), attendanceGoOut.getOutEndTime().toLocalDateTime()) |
| | | ).collect(Collectors.toList()) |
| | | ); |
| | | // 周末加班 |
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(userId, startOfDate, endOfDate); |
| | | attendanceParts.addAll( |
| | | attendanceOvertimeList.stream().map(attendanceOvertime -> |
| | | new Calculate(attendanceOvertime.getOvertimeStartTime().toLocalDateTime(), attendanceOvertime.getOvertimeEndTime().toLocalDateTime()) |
| | | ).collect(Collectors.toList()) |
| | | ); |
| | | attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), (result, current) -> { |
| | | // 删除重复时间,合并相连的时间段 |
| | | if (result.empty()) { |
| | | result.push(current); |
| | | return result; |
| | | } |
| | | Calculate last = result.peek(); |
| | | if (last.getEnd().isBefore(current.getStart())) { |
| | | result.push(current); |
| | | } else if (last.getEnd().isBefore(current.getEnd())) { |
| | | last.setEnd(current.getEnd()); |
| | | } |
| | | return result; |
| | | }, (o1, o2) -> null).forEach(calculate -> { |
| | | // 去除休息时间:午休等 |
| | | for (Calculate breakPart : breakParts) { |
| | | if ((calculate.getStart().isBefore(breakPart.getStart()) && calculate.getEnd().isAfter(breakPart.getStart())) |
| | | || (calculate.getStart().isBefore(breakPart.getEnd()) && calculate.getEnd().isAfter(breakPart.getEnd()))) { |
| | | Calculate calculate1 = new Calculate(calculate.getStart(), breakPart.getStart()); |
| | | Calculate calculate2 = new Calculate(breakPart.getEnd(), calculate.getEnd()); |
| | | if (calculate1.getStart().isBefore(calculate1.getEnd())) { |
| | | resultParts.add(calculate1); |
| | | } |
| | | if (calculate2.getStart().isBefore(calculate2.getEnd())) { |
| | | resultParts.add(calculate2); |
| | | } |
| | | } else { |
| | | resultParts.add(calculate); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // 请假信息 |
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(userId, startOfDate, endOfDate); |
| | | // // 加班信息 |
| | | // List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(userId, startOfDate, endOfDate); |
| | | |
| | | // 出勤时间累计 |
| | | BigDecimal result = resultParts.stream() |
| | | .map(calculate -> ChronoUnit.SECONDS.between(calculate.getStart(), calculate.getEnd())) |
| | | .reduce(new BigDecimal(0), |
| | | (total, current) -> total.add(BigDecimal.valueOf(current)), |
| | | (o1, o2) -> null).divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP |
| | | ); |
| | | BigDecimal annualLeaveHours = attendanceLeaveList.stream() |
| | | .filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType()) |
| | | || Constant.LEAVE_TYPE_MARRIAGE_HOLIDAY.equals(attendanceLeave.getLeaveType()) |
| | | || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType()) |
| | | // || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType()) |
| | | ).map(attendanceLeave -> BigDecimal.valueOf(attendanceLeave.getLeaveDuration())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); |
| | | return result.add(annualLeaveHours).doubleValue(); |
| | | } |
| | | |
| | | @Override |
| | | public Double queryAttendanceHolidaysOverTimeHours(NewAttendanceQueryCriteria criteria) { |
| | | |
| | | LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDate endDate = startDate.plusMonths(1).minusDays(1); |
| | | // 节日检索类 |
| | | SysConfigHolidayQueryCriteria sysConfigHolidayQueryCriteria = new SysConfigHolidayQueryCriteria(); |
| | | sysConfigHolidayQueryCriteria.setHolidayDateLike(criteria.getTargetYearMonth().substring(0, 7)); |
| | | // 获取本月节日列表 |
| | | List<SysConfigHoliday> sysConfigHolidayMonthList = sysConfigHolidayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, sysConfigHolidayQueryCriteria, criteriaBuilder)); |
| | | if (sysConfigHolidayMonthList.isEmpty()) { |
| | | return 0.0D; |
| | | } |
| | | // 加班信息 |
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserIdAndDate(criteria.getUserId(), startDate.atStartOfDay(), endDate.atStartOfDay()); |
| | | |
| | | return sysConfigHolidayMonthList.stream() |
| | | .filter(sysConfigHoliday -> Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(sysConfigHoliday.getDateType())) |
| | | .mapToDouble(sysConfigHoliday -> { |
| | | for (AttendanceOvertime attendanceOvertime : attendanceOvertimeList) { |
| | | if (sysConfigHoliday.getHolidayDate().toLocalDateTime().isEqual(attendanceOvertime.getOvertimeStartTime().toLocalDateTime().truncatedTo(ChronoUnit.DAYS))) { |
| | | return attendanceOvertime.getOvertimeDuration(); |
| | | } |
| | | } |
| | | return 0.0D; |
| | | }).sum(); |
| | | } |
| | | |
| | | @Override |
| | | public Double queryAttendanceOverTimeHours(NewAttendanceQueryCriteria criteria) { |
| | | // 节日检索类 |
| | | SysConfigHolidayQueryCriteria sysConfigHolidayQueryCriteria = new SysConfigHolidayQueryCriteria(); |
| | | sysConfigHolidayQueryCriteria.setHolidayDateLike(criteria.getTargetYearMonth().substring(0, 7)); |
| | | // 获取本月节日列表 |
| | | List<SysConfigHoliday> sysConfigHolidayMonthList = sysConfigHolidayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, sysConfigHolidayQueryCriteria, criteriaBuilder)); |
| | | |
| | | LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDate endDate = startDate.plusMonths(1).minusDays(1); |
| | | |
| | | Long distance = ChronoUnit.DAYS.between(startDate, endDate); |
| | | |
| | | return Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).filter(localDate -> { |
| | | for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayMonthList) { |
| | | if (sysConfigHoliday.getHolidayDate().toLocalDateTime().isEqual(localDate.atStartOfDay())) { |
| | | return Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHoliday.getDateType()); |
| | | } |
| | | } |
| | | return localDate.getDayOfWeek() != DayOfWeek.SATURDAY && localDate.getDayOfWeek() != DayOfWeek.SUNDAY; |
| | | }).map(localDate -> { |
| | | LocalDateTime startOfDate = localDate.atTime(0, 0, 0); |
| | | LocalDateTime endOfDate = localDate.atTime(23, 59, 59); |
| | | NewAttendance attendanceDate = newAttendanceRepository.findAllByUserIdAndAttendanceDate(criteria.getUserId(), localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | if (attendanceDate == null) { |
| | | return BigDecimal.valueOf(0.0); |
| | | } |
| | | LocalDateTime actualWorkStartTime = attendanceDate.getActualWorkStartTime() == null ? null : attendanceDate.getActualWorkStartTime().toLocalDateTime(); |
| | | LocalDateTime actualWorkEndTime = attendanceDate.getActualWorkEndTime() == null ? null : attendanceDate.getActualWorkEndTime().toLocalDateTime(); |
| | | |
| | | LocalDateTime rosteringWorkStartTime = attendanceDate.getRosteringWorkStartTime() == null ? null : attendanceDate.getRosteringWorkStartTime().toLocalDateTime(); |
| | | LocalDateTime rosteringWorkEndTime = attendanceDate.getRosteringWorkEndTime() == null ? null : attendanceDate.getRosteringWorkEndTime().toLocalDateTime(); |
| | | if (actualWorkStartTime != null && actualWorkStartTime.isBefore(rosteringWorkStartTime)) { |
| | | actualWorkStartTime = rosteringWorkStartTime; |
| | | } |
| | | List<Calculate> attendanceParts = new ArrayList<>(); |
| | | // 当日打卡信息不全不算 |
| | | if (actualWorkStartTime != null && actualWorkEndTime != null) { |
| | | attendanceParts.add(new Calculate(actualWorkStartTime, actualWorkEndTime)); |
| | | } |
| | | |
| | | // 正常时间管理 |
| | | List<Calculate> breakParts = new ArrayList<>(); |
| | | breakParts.add(new Calculate(rosteringWorkStartTime, rosteringWorkEndTime.plusMinutes(30))); |
| | | |
| | | // 外出信息 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(criteria.getUserId(), startOfDate, endOfDate); |
| | | attendanceParts.addAll( |
| | | attendanceGoOutList.stream().map(attendanceGoOut -> { |
| | | LocalDateTime attendanceGoOutStart = attendanceGoOut.getOutStartTime().toLocalDateTime(); |
| | | LocalDateTime attendanceGoOutEnd = attendanceGoOut.getOutEndTime().toLocalDateTime(); |
| | | if (attendanceGoOutStart.isBefore(rosteringWorkStartTime)) { |
| | | attendanceGoOutStart = rosteringWorkStartTime; |
| | | } |
| | | return new Calculate(attendanceGoOutStart, attendanceGoOutEnd); |
| | | }).filter(calculate -> calculate.getStart().isBefore(calculate.getEnd())).collect(Collectors.toList()) |
| | | ); |
| | | |
| | | List<Calculate> resultParts = new ArrayList<>(); |
| | | |
| | | attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), (result, current) -> { |
| | | // 删除重复时间,合并相连的时间段 |
| | | if (result.empty()) { |
| | | result.push(current); |
| | | return result; |
| | | } |
| | | Calculate last = result.peek(); |
| | | if (last.getEnd().isBefore(current.getStart())) { |
| | | result.push(current); |
| | | } else if (last.getEnd().isBefore(current.getEnd())) { |
| | | last.setEnd(current.getEnd()); |
| | | } |
| | | return result; |
| | | }, (o1, o2) -> null).forEach(calculate -> { |
| | | // 去除休息时间:午休等 |
| | | for (Calculate breakPart : breakParts) { |
| | | if ((!calculate.getStart().isAfter(breakPart.getStart()) && !calculate.getEnd().isBefore(breakPart.getStart())) |
| | | || (!calculate.getStart().isAfter(breakPart.getEnd()) && !calculate.getEnd().isBefore(breakPart.getEnd()))) { |
| | | Calculate calculate1 = new Calculate(calculate.getStart(), breakPart.getStart()); |
| | | Calculate calculate2 = new Calculate(breakPart.getEnd(), calculate.getEnd()); |
| | | if (calculate1.getStart().isBefore(calculate1.getEnd())) { |
| | | resultParts.add(calculate1); |
| | | } |
| | | if (calculate2.getStart().isBefore(calculate2.getEnd())) { |
| | | resultParts.add(calculate2); |
| | | } |
| | | } else if (calculate.getEnd().isBefore(breakPart.getStart()) || calculate.getStart().isAfter(breakPart.getEnd())) { |
| | | resultParts.add(calculate); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // 出勤时间累计 |
| | | Long result = resultParts.stream() |
| | | .mapToLong(calculate -> ChronoUnit.MINUTES.between(calculate.getStart(), calculate.getEnd())) |
| | | .sum(); |
| | | // .reduce(new BigDecimal(0), |
| | | // (total, current) -> total.add(BigDecimal.valueOf(current)), |
| | | // (o1, o2) -> null).divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP |
| | | // ) |
| | | // result = result.setScale(1, RoundingMode.FLOOR); |
| | | // if (result < 30) { |
| | | // System.out.println("localDate : " + localDate + " hours : " + 0); |
| | | // return BigDecimal.valueOf(0.0); |
| | | // } else { |
| | | // result = result - 30; |
| | | // } |
| | | System.out.println("localDate : " + localDate + " hours : " + result); |
| | | return BigDecimal.valueOf(result).divide(BigDecimal.valueOf(60), 1, RoundingMode.HALF_DOWN); |
| | | }).reduce(BigDecimal::add).get().doubleValue(); |
| | | } |
| | | |
| | | @Override |
| | | public Double queryAttendanceHours(NewAttendanceQueryCriteria criteria) { |
| | | // 节日检索类 |
| | | SysConfigHolidayQueryCriteria sysConfigHolidayQueryCriteria = new SysConfigHolidayQueryCriteria(); |
| | | sysConfigHolidayQueryCriteria.setHolidayDateLike(criteria.getTargetYearMonth().substring(0, 7)); |
| | | // 获取本月节日列表 |
| | | List<SysConfigHoliday> sysConfigHolidayMonthList = sysConfigHolidayRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, sysConfigHolidayQueryCriteria, criteriaBuilder)); |
| | | |
| | | LocalDate startDate = LocalDate.parse(criteria.getTargetYearMonth(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDate endDate = startDate.plusMonths(1).minusDays(1); |
| | | |
| | | Long distance = ChronoUnit.DAYS.between(startDate, endDate); |
| | | |
| | | return Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).filter(localDate -> { |
| | | for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayMonthList) { |
| | | if (sysConfigHoliday.getHolidayDate().toLocalDateTime().isEqual(localDate.atStartOfDay())) { |
| | | return Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHoliday.getDateType()); |
| | | } |
| | | } |
| | | return localDate.getDayOfWeek() != DayOfWeek.SATURDAY && localDate.getDayOfWeek() != DayOfWeek.SUNDAY; |
| | | }).map(localDate -> { |
| | | System.out.print("localDate : " + localDate); |
| | | LocalDateTime startOfDate = localDate.atTime(0, 0, 0); |
| | | LocalDateTime endOfDate = localDate.atTime(23, 59, 59); |
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(criteria.getUserId(), startOfDate, endOfDate); |
| | | if (attendanceBusinessTravel != null) { |
| | | System.out.println("\t hours1 : " + 8); |
| | | return BigDecimal.valueOf(8.0); |
| | | } |
| | | NewAttendance attendanceDate = newAttendanceRepository.findAllByUserIdAndAttendanceDate(criteria.getUserId(), localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | if (attendanceDate == null) { |
| | | System.out.println("\t hours2 : " + 0); |
| | | return BigDecimal.valueOf(0.0); |
| | | } |
| | | LocalDateTime actualWorkStartTime = attendanceDate.getActualWorkStartTime() == null ? null : attendanceDate.getActualWorkStartTime().toLocalDateTime(); |
| | | LocalDateTime actualWorkEndTime = attendanceDate.getActualWorkEndTime() == null ? null : attendanceDate.getActualWorkEndTime().toLocalDateTime(); |
| | | |
| | | LocalDateTime rosteringWorkStartTime = attendanceDate.getRosteringWorkStartTime() == null ? null : attendanceDate.getRosteringWorkStartTime().toLocalDateTime(); |
| | | LocalDateTime rosteringLunchStartTime = attendanceDate.getRosteringLunchStartTime() == null ? null : attendanceDate.getRosteringLunchStartTime().toLocalDateTime(); |
| | | LocalDateTime rosteringLunchEndTime = attendanceDate.getRosteringLunchEndTime() == null ? null : attendanceDate.getRosteringLunchEndTime().toLocalDateTime(); |
| | | LocalDateTime rosteringWorkEndTime = attendanceDate.getRosteringWorkEndTime() == null ? null : attendanceDate.getRosteringWorkEndTime().toLocalDateTime(); |
| | | if (actualWorkStartTime != null && actualWorkStartTime.isBefore(rosteringWorkStartTime)) { |
| | | actualWorkStartTime = rosteringWorkStartTime; |
| | | } |
| | | if (actualWorkEndTime != null && actualWorkEndTime.isAfter(rosteringWorkEndTime)) { |
| | | actualWorkEndTime = rosteringWorkEndTime; |
| | | } |
| | | List<Calculate> attendanceParts = new ArrayList<>(); |
| | | // 当日打卡信息不全不算 |
| | | if (actualWorkStartTime != null && actualWorkEndTime != null) { |
| | | attendanceParts.add(new Calculate(actualWorkStartTime, actualWorkEndTime)); |
| | | } |
| | | |
| | | // 休息时间管理 |
| | | List<Calculate> breakParts = new ArrayList<>(); |
| | | breakParts.add(new Calculate(rosteringLunchStartTime, rosteringLunchEndTime)); |
| | | |
| | | // 外出信息 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(criteria.getUserId(), startOfDate, endOfDate); |
| | | attendanceParts.addAll( |
| | | attendanceGoOutList.stream().map(attendanceGoOut -> { |
| | | LocalDateTime attendanceGoOutStart = attendanceGoOut.getOutStartTime().toLocalDateTime(); |
| | | LocalDateTime attendanceGoOutEnd = attendanceGoOut.getOutEndTime().toLocalDateTime(); |
| | | if (attendanceGoOutStart.isBefore(rosteringWorkStartTime)) { |
| | | attendanceGoOutStart = rosteringWorkStartTime; |
| | | } |
| | | if (attendanceGoOutEnd.isAfter(rosteringWorkEndTime)) { |
| | | attendanceGoOutEnd = rosteringWorkEndTime; |
| | | } |
| | | return new Calculate(attendanceGoOutStart, attendanceGoOutEnd); |
| | | }).filter(calculate -> calculate.getStart().isBefore(calculate.getEnd())).collect(Collectors.toList()) |
| | | ); |
| | | |
| | | List<Calculate> resultParts = new ArrayList<>(); |
| | | |
| | | attendanceParts.stream().sorted().reduce(new Stack<Calculate>(), (result, current) -> { |
| | | // 删除重复时间,合并相连的时间段 |
| | | if (result.empty()) { |
| | | result.push(current); |
| | | return result; |
| | | } |
| | | Calculate last = result.peek(); |
| | | if (last.getEnd().isBefore(current.getStart())) { |
| | | result.push(current); |
| | | } else if (last.getEnd().isBefore(current.getEnd())) { |
| | | last.setEnd(current.getEnd()); |
| | | } |
| | | return result; |
| | | }, (o1, o2) -> null).forEach(calculate -> { |
| | | // 去除休息时间:午休等 |
| | | for (Calculate breakPart : breakParts) { |
| | | if ((calculate.getStart().isBefore(breakPart.getStart()) && calculate.getEnd().isAfter(breakPart.getStart())) |
| | | || (calculate.getStart().isBefore(breakPart.getEnd()) && calculate.getEnd().isAfter(breakPart.getEnd()))) { |
| | | Calculate calculate1 = new Calculate(calculate.getStart(), breakPart.getStart()); |
| | | Calculate calculate2 = new Calculate(breakPart.getEnd(), calculate.getEnd()); |
| | | if (calculate1.getStart().isBefore(calculate1.getEnd())) { |
| | | resultParts.add(calculate1); |
| | | } |
| | | if (calculate2.getStart().isBefore(calculate2.getEnd())) { |
| | | resultParts.add(calculate2); |
| | | } |
| | | } else { |
| | | resultParts.add(calculate); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // 出勤时间累计 |
| | | BigDecimal result = resultParts.stream() |
| | | .map(calculate -> ChronoUnit.SECONDS.between(calculate.getStart(), calculate.getEnd())) |
| | | .reduce(new BigDecimal(0), |
| | | (total, current) -> total.add(BigDecimal.valueOf(current)), |
| | | (o1, o2) -> null).divide(BigDecimal.valueOf(3600), 2, RoundingMode.HALF_UP |
| | | ); |
| | | |
| | | // 请假信息 |
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(criteria.getUserId(), startOfDate, endOfDate); |
| | | // 年假不扣工时 |
| | | BigDecimal annualLeaveHours = attendanceLeaveList.stream() |
| | | .filter(attendanceLeave -> Constant.LEAVE_TYPE_ANNUAL_LEAVE.equals(attendanceLeave.getLeaveType()) |
| | | || Constant.LEAVE_TYPE_MARRIAGE_HOLIDAY.equals(attendanceLeave.getLeaveType()) |
| | | || Constant.LEAVE_TYPE_BEREAVEMENT_LEAVE.equals(attendanceLeave.getLeaveType()) |
| | | || Constant.LEAVE_TYPE_REPLACE.equals(attendanceLeave.getLeaveType())) |
| | | .map(attendanceLeave -> { |
| | | if (Constant.LEAVE_TIME_TYPE_HOUR.equals(attendanceLeave.getLeaveDurationUnit())) { |
| | | return BigDecimal.valueOf(attendanceLeave.getLeaveDuration()); |
| | | } else { |
| | | return BigDecimal.valueOf(attendanceLeave.getLeaveDuration()).multiply(BigDecimal.valueOf(8)); |
| | | } |
| | | }).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); |
| | | if (result.add(annualLeaveHours).compareTo(BigDecimal.valueOf(8.0)) > 0) { |
| | | System.out.println("\t hours3 : " + 8); |
| | | return BigDecimal.valueOf(8.0); |
| | | } |
| | | System.out.println("\t hours4 : " + result.add(annualLeaveHours)); |
| | | return result.add(annualLeaveHours); |
| | | }).reduce(BigDecimal::add).get().doubleValue(); |
| | | } |
| | | |
| | | /** |
| | | * 设置日历类 |
| | | * |
| | | * @return |
| | | */ |
| | | private Calendar setUpCalendar(String targetYearMonth) { |
| | | // 日历类 |
| | | Calendar cal = Calendar.getInstance(); |
| | | // 设置年份 |
| | | cal.set(Calendar.YEAR, Integer.valueOf(targetYearMonth.substring(0, 4))); |
| | | // 设置月份 |
| | | cal.set(Calendar.MONTH, Integer.valueOf(targetYearMonth.substring(5, 7)) - 1); |
| | | // 日历类 |
| | | return cal; |
| | | } |
| | | |
| | | /** |
| | | * 获取有效时长 |
| | | * |
| | | * @param attendanceDay |
| | | * @param startTime |
| | | * @param endTime |
| | | * @return |
| | | */ |
| | | private Long getValidDuration(Attendance attendanceDay, Timestamp startTime, Timestamp endTime) { |
| | | // 判断开始时间与结束时间 |
| | | if (endTime.getTime() < startTime.getTime()) { |
| | | throw new BadRequestException("结束时间应大于开始时间!"); |
| | | } |
| | | // 判断开始时间 |
| | | if (startTime.getTime() < attendanceDay.getRosteringWorkStartTime().getTime()) { |
| | | // 判断结束时间 |
| | | if (endTime.getTime() < attendanceDay.getRosteringWorkStartTime().getTime()) { |
| | | // 返回有效时长 = 0 |
| | | return 0L; |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) { |
| | | // 返回有效时长 = 结束时间 - 排班工作开始时间 |
| | | return endTime.getTime() - attendanceDay.getRosteringWorkStartTime().getTime(); |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) { |
| | | // 返回有效时长 = 排班午休开始时间 - 排班工作开始时间 |
| | | return attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime(); |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 返回有效时长 = (排班午休开始时间 - 排班工作开始时间) + (结束时间 - 排班午休结束时间) |
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime()) + (endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime()); |
| | | } else { |
| | | // 返回有效时长 = (排班午休开始时间 - 排班工作开始时间) + (排班工作结束时间 - 排班午休结束时间) |
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - attendanceDay.getRosteringWorkStartTime().getTime()) + (attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime()); |
| | | } |
| | | } else if (startTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) { |
| | | // 判断结束时间 |
| | | if (endTime.getTime() < attendanceDay.getRosteringLunchStartTime().getTime()) { |
| | | // 返回有效时长 = 结束时间 - 开始时间 |
| | | return endTime.getTime() - startTime.getTime(); |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) { |
| | | // 返回有效时长 = 排班午休开始时间 - 开始时间 |
| | | return attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime(); |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 返回有效时长 = (排班午休开始时间 - 开始时间) + (结束时间 - 排班午休结束时间) |
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime()) + (endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime()); |
| | | } else { |
| | | // 返回有效时长 = (排班午休开始时间 - 开始时间) + (排班工作结束时间 - 排班午休结束时间) |
| | | return (attendanceDay.getRosteringLunchStartTime().getTime() - startTime.getTime()) + (attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime()); |
| | | } |
| | | } else if (startTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) { |
| | | // 判断结束时间 |
| | | if (endTime.getTime() < attendanceDay.getRosteringLunchEndTime().getTime()) { |
| | | // 返回有效时长 = 0 |
| | | return 0L; |
| | | } else if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 返回有效时长 = 结束时间 - 排班午休结束时间 |
| | | return endTime.getTime() - attendanceDay.getRosteringLunchEndTime().getTime(); |
| | | } else { |
| | | // 返回有效时长 = 排班工作结束时间 - 排班午休结束时间 |
| | | return attendanceDay.getRosteringWorkEndTime().getTime() - attendanceDay.getRosteringLunchEndTime().getTime(); |
| | | } |
| | | } else if (startTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 判断结束时间 |
| | | if (endTime.getTime() < attendanceDay.getRosteringWorkEndTime().getTime()) { |
| | | // 返回有效时长 = 结束时间 - 开始时间 |
| | | return endTime.getTime() - startTime.getTime(); |
| | | } else { |
| | | // 返回有效时长 = 排班工作结束时间 - 开始时间 |
| | | return attendanceDay.getRosteringWorkEndTime().getTime() - startTime.getTime(); |
| | | } |
| | | } else { |
| | | // 返回有效时长 = 0 |
| | | return 0L; |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.NewAttendance; |
| | | import me.zhengjie.modules.attendance.service.dto.NewAttendanceDto; |
| | | import org.mapstruct.Mapper; |
| | | import org.mapstruct.ReportingPolicy; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | | * @author baolh |
| | | * @date 2025-03-12 |
| | | **/ |
| | | @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) |
| | | public interface NewAttendanceMapper extends BaseMapper<NewAttendanceDto, NewAttendance> { |
| | | |
| | | } |
| New file |
| | |
| | | package me.zhengjie.modules.quartz.service.impl; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import me.chanjar.weixin.cp.api.WxCpService; |
| | | import me.chanjar.weixin.cp.bean.oa.WxCpCheckinData; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | import me.zhengjie.modules.attendance.repository.*; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | 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 me.zhengjie.utils.StringUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class WeComServiceImpl { |
| | | private final WxCpService wxCpService; |
| | | private final NewAttendanceRepository attendanceRepository; |
| | | private final UserRepository userRepository; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final SysRosteringRepository sysRosteringRepository; |
| | | private final AttendanceCardreplacementRepository attendanceCardreplacementRepository; |
| | | private final AttendanceLeaveRepository attendanceLeaveRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | |
| | | /** |
| | | * 凌晨0点执行,新增用户考勤信息 |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void getWeComAttendanceList(Timestamp attendDate, List attUser) throws Exception { |
| | | // 日期格式化 |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 获取当前日期 |
| | | String strTodayDate = df.format(new Date()); |
| | | // 获取考勤日期类 |
| | | Calendar calAttendDay = Calendar.getInstance(); |
| | | // 参数日期为null(定时任务) |
| | | if (ObjectUtils.isEmpty(attendDate)) { |
| | | // 考勤日期类 |
| | | calAttendDay.setTime(Timestamp.valueOf(strTodayDate + " 00:00:00")); |
| | | } else { |
| | | // 考勤日期类 |
| | | calAttendDay.setTime(attendDate); |
| | | } |
| | | // 参数日期为null(定时任务) 或者 参数日期小于等于今天在创建(考勤按钮调用) |
| | | if (ObjectUtils.isEmpty(attendDate) || attendDate.compareTo(Timestamp.valueOf(strTodayDate + " 00:00:00")) <= 0) { |
| | | // 用户列表 |
| | | List<User> userList = new ArrayList<>(); |
| | | // 参数用户不为空(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attUser)) { |
| | | // 用户列表 |
| | | userList = attUser; |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | } else { |
| | | // 用户列表:查询状态正常的员工 |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | } |
| | | // 参数日期 |
| | | String strAttendDate = ""; |
| | | // 节假日列表 |
| | | SysConfigHoliday sysConfigHoliday; |
| | | // 参数日期不为null(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 参数日期 |
| | | strAttendDate = df.format(attendDate); |
| | | // 节假日列表 |
| | | sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(strAttendDate); |
| | | } else { |
| | | // 节假日列表 |
| | | sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(strTodayDate); |
| | | } |
| | | // 遍历用户列表 |
| | | for (User user : userList) { |
| | | // 用户排班 |
| | | SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getSysRostering().getId()); |
| | | // 考勤记录 |
| | | NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), (ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate)); |
| | | // 考勤记录为null |
| | | if (ObjectUtil.isEmpty(attendance)) { |
| | | // 新建考勤记录 |
| | | attendance = new NewAttendance(); |
| | | } |
| | | // 考勤记录 |
| | | attendance.setUserId(user.getId()); |
| | | attendance.setAttendanceDate(Timestamp.valueOf(ObjectUtils.isEmpty(attendDate) ? strTodayDate + " 00:00:00" : strAttendDate + " 00:00:00")); |
| | | attendance.setStartClockResults((ObjectUtil.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NORMAL)) ? attendance.getStartClockResults() : Constant.ATTENDANCE_STATE_WAITFOR); |
| | | attendance.setEndClockResults((ObjectUtil.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NORMAL)) ? attendance.getEndClockResults() : Constant.ATTENDANCE_STATE_WAITFOR); |
| | | // 考勤日期类是否是周末、节假日、工作日 |
| | | if (sysConfigHoliday == null && (calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) { |
| | | // 考勤记录:日期类型-双休 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKEND); |
| | | } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) { |
| | | // 考勤记录:日期类型-节假日 |
| | | attendance.setDateType(Constant.DATE_TYPE_LEGAL_HOLIDAYS); |
| | | } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) { |
| | | // 考勤记录:日期类型-法定节假日 |
| | | attendance.setDateType(Constant.DATE_TYPE_HOLIDAYS); |
| | | } else { |
| | | // 考勤记录:日期类型-工作日 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKDAY); |
| | | } |
| | | // 时间格式化 |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | // 考勤记 |
| | | attendance.setRosteringWorkStartTime(Timestamp.valueOf((ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate) + " " + dateTimeFormatter.format(sysRostering.getWorkStartTime()))); |
| | | attendance.setRosteringWorkEndTime(Timestamp.valueOf((ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate) + " " + dateTimeFormatter.format(sysRostering.getWorkEndTime()))); |
| | | attendance.setRosteringLunchStartTime(Timestamp.valueOf((ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate) + " " + dateTimeFormatter.format(sysRostering.getLunchStartTime()))); |
| | | attendance.setRosteringLunchEndTime(Timestamp.valueOf((ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate) + " " + dateTimeFormatter.format(sysRostering.getLunchEndTime()))); |
| | | // 保存 |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 中午12点30执行,更新早打卡情况 |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void getWeComAttendanceListOfNoon(String attendDate, List attUser) throws Exception { |
| | | try { |
| | | // 获取企业微信Token |
| | | String weComAccessToken = wxCpService.getAccessToken(); |
| | | |
| | | // 日期格式化 |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 参数日期 |
| | | String strAttendDate = ""; |
| | | // 参数日期不为null(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 参数日期 |
| | | strAttendDate = attendDate; |
| | | } else { |
| | | // 参数日期 |
| | | strAttendDate = df.format(new Date()); |
| | | } |
| | | // 获取参数日期类 |
| | | Calendar calAttendDate = Calendar.getInstance(); |
| | | calAttendDate.setTime(Timestamp.valueOf(strAttendDate + " 00:00:00")); |
| | | // 用户列表 |
| | | List<User> userList; |
| | | // 参数用户不为空(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attUser)) { |
| | | // 用户列表 |
| | | userList = attUser; |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | } else { |
| | | // 用户列表:查询状态正常的员工 |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | } |
| | | // 遍历用户列表 |
| | | for (User user : userList) { |
| | | // 考勤记录:根据用户和日期查询 |
| | | NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate); |
| | | // 如果是周六或者周日或节假日,打卡状态为等待的话,就改状态为休息(返回结果为空数组的情况下) |
| | | if (ObjectUtils.isNotEmpty(attendance) && (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS))) { |
| | | // 开始打卡结果 |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST); |
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST); |
| | | attendance.setActualWorkStartTime(null); |
| | | } |
| | | // 结束打卡结果 |
| | | if (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST); |
| | | attendance.setActualWorkEndTime(null); |
| | | } |
| | | } |
| | | // 企业微信ID |
| | | List<String> userWeComList = new ArrayList<>(); |
| | | userWeComList.add(user.getWeComId()); |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | // 早打卡 |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), new Timestamp(weComRecordResult.getCheckinTime() * 1000), 1))); |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : new Timestamp(weComRecordResult.getCheckinTime() * 1000)); |
| | | } |
| | | // 晚打卡 |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), new Timestamp(weComRecordResult.getCheckinTime() * 1000), 2))); |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : new Timestamp(weComRecordResult.getCheckinTime() * 1000)); |
| | | } |
| | | } |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | attendance = updateRecord(user, attendance, true, attendDate); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 凌晨02:30执行,更新晚打卡情况 |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void getWeComAttendanceListOfNight(String attendDate, List attUser) throws Exception { |
| | | // 获取企业微信Token |
| | | String weComAccessToken = wxCpService.getAccessToken(); |
| | | |
| | | try { |
| | | // 获取参数日期类 |
| | | Calendar calAttendDate = Calendar.getInstance(); |
| | | // 日期格式化 |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 参数日期 |
| | | String strAttendDate = ""; |
| | | // 参数日期不为null(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 参数日期 |
| | | strAttendDate = attendDate; |
| | | } else { |
| | | // 参数日期类 |
| | | calAttendDate.add(Calendar.DATE, -1); |
| | | // 参数日期 |
| | | strAttendDate = df.format(calAttendDate.getTime()); |
| | | } |
| | | // 参数日期类 |
| | | calAttendDate.setTime(Timestamp.valueOf(strAttendDate + " 00:00:00")); |
| | | // 用户列表 |
| | | List<User> userList; |
| | | // 参数用户不为空(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attUser)) { |
| | | // 用户列表 |
| | | userList = attUser; |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | } else { |
| | | // 用户列表:查询状态正常的员工 |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | } |
| | | // 遍历用户列表 |
| | | for (User user : userList) { |
| | | // 考勤记录:根据用户和日期查询 |
| | | NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate); |
| | | // 如果是周六或者周日或节假日,打卡状态为等待的话,就改状态为休息(oapiDingTalkRecordResultList为空的情况下) |
| | | if (ObjectUtils.isNotEmpty(attendance) && (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS))) { |
| | | // 开始打卡结果 |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST); |
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST); |
| | | attendance.setActualWorkStartTime(null); |
| | | } |
| | | // 结束打卡结果 |
| | | if (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST); |
| | | attendance.setActualWorkEndTime(null); |
| | | } |
| | | } |
| | | // 企业微信ID |
| | | List<String> userWeComList = new ArrayList<>(); |
| | | userWeComList.add(user.getWeComId()); |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | // 早打卡 |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), new Timestamp(weComRecordResult.getCheckinTime() * 1000), 1))); |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : new Timestamp(weComRecordResult.getCheckinTime() * 1000)); |
| | | } |
| | | // 晚打卡 |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), new Timestamp(weComRecordResult.getCheckinTime() * 1000), 2))); |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : new Timestamp(weComRecordResult.getCheckinTime() * 1000)); |
| | | } |
| | | } |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | attendance = updateRecord(user, attendance, false, attendDate); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 中午12点30或凌晨02:30执行定时任务 |
| | | * @throws Exception |
| | | */ |
| | | public void getWeComAttendanceListOfNoonOrNight(String attendDate, List attUser) throws Exception { |
| | | // 中午12点30执行,更新早打卡情况 |
| | | getWeComAttendanceListOfNoon(attendDate, attUser); |
| | | // 凌晨02:30执行,更新晚打卡情况 |
| | | getWeComAttendanceListOfNight(attendDate, attUser); |
| | | } |
| | | |
| | | /** |
| | | * 查询其他状态表并调用方法修改 |
| | | * |
| | | * @param user |
| | | */ |
| | | public NewAttendance updateRecord(User user, NewAttendance attendance, Boolean day, String attendDate) { |
| | | // 查询考勤请假表 |
| | | List<AttendanceLeave> attendanceLeaveLists = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | for (AttendanceLeave attendanceLeave : attendanceLeaveLists) { |
| | | // 上午/下午/全天 |
| | | if (attendanceLeave.getLeaveStartTime().toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && attendanceLeave.getLeaveEndTime().toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) { |
| | | getMornOrNoon(user, attendance, attendDate, attendance.getRosteringWorkStartTime(), attendance.getRosteringLunchEndTime(), day); |
| | | } else if (attendanceLeave.getLeaveStartTime().toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0 && attendanceLeave.getLeaveEndTime().toLocalDateTime().compareTo(attendance.getRosteringWorkEndTime().toLocalDateTime()) <= 0) { |
| | | getMornOrNoon(user, attendance, attendDate, attendance.getRosteringLunchStartTime(), attendance.getRosteringWorkEndTime(), day); |
| | | } else { |
| | | getMornOrNoon(user, attendance, attendDate, attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), day); |
| | | } |
| | | } |
| | | //查询出差表 |
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime()); |
| | | if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) { |
| | | getMornOrNoon(user, attendance, attendDate, attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), day); |
| | | } |
| | | // 查询外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // 上午/下午 |
| | | if (attendanceGoOut.getOutStartTime().toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && attendanceGoOut.getOutEndTime().toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) { |
| | | getMornOrNoon(user, attendance, attendDate, attendance.getRosteringWorkStartTime(), attendance.getRosteringLunchEndTime(), day); |
| | | } else if (attendanceGoOut.getOutStartTime().toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0 && attendanceGoOut.getOutEndTime().toLocalDateTime().compareTo(attendance.getRosteringWorkEndTime().toLocalDateTime()) <= 0) { |
| | | getMornOrNoon(user, attendance, attendDate, attendance.getRosteringLunchStartTime(), attendance.getRosteringWorkEndTime(), day); |
| | | } else { |
| | | getMornOrNoon(user, attendance, attendDate, attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), day); |
| | | } |
| | | } |
| | | return attendance; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 请假优先于出差优先于外出 |
| | | * |
| | | * @param user |
| | | * @param attendance |
| | | * @param attendDate |
| | | * @param startDate |
| | | * @param endDate |
| | | */ |
| | | public void getMornOrNoon(User user, NewAttendance attendance, String attendDate, Timestamp startDate, Timestamp endDate, Boolean day) { |
| | | // 查询考勤请假表 |
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), startDate.toLocalDateTime(), endDate.toLocalDateTime()); |
| | | Double leaveDuration = new Double(0.00);//计算的总时长 |
| | | Double leaveStartDuration = new Double(0.00);//考勤按钮的时长 |
| | | Double leaveEndDuration = new Double(0.00);//考勤按钮的时长 |
| | | // 请假优先于出差优先于外出 |
| | | if (attendanceLeaveList.size() < 1) { |
| | | // 查询考勤出差表 |
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime()); |
| | | Double bussDuration = new Double(0.00); |
| | | Double bussStartDuration = new Double(0.00);//考勤按钮的时长 |
| | | Double bussEndDuration = new Double(0.00);//考勤按钮的时长 |
| | | if (ObjectUtils.isEmpty(attendanceBusinessTravel)) { |
| | | // 查询考勤外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | Double outDuration = new Double(0.00); |
| | | Double outStartDuration = new Double(0.00);// 考勤按钮的时长 |
| | | Double outEndDuration = new Double(0.00);// 考勤按钮的时长 |
| | | for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // attendDate不等于null 说明是考勤信息按钮 |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 上午时长、下午时长 |
| | | outStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | outEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | // 调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, outStartDuration, outEndDuration); |
| | | } else { |
| | | // 上午or下午总时长 |
| | | outDuration += getDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance, day); |
| | | updateAttendanceRecord(outDuration, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, null, null); |
| | | } |
| | | } |
| | | } else { |
| | | if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) { |
| | | // attendDate不等于null 说明是考勤信息按钮 |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 上午时长、下午时长 |
| | | bussStartDuration += getStartDuration(attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), attendance); |
| | | bussEndDuration += getEndDuration(attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), attendance); |
| | | //调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, bussStartDuration, bussEndDuration); |
| | | } else { |
| | | // 上午or下午总时长 |
| | | bussDuration += getDuration(attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), attendance, day); |
| | | updateAttendanceRecord(bussDuration, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, null, null); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | // 查询考勤外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // attendDate不等于null 说明是考勤信息按钮 |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 上午时长、下午时长 |
| | | leaveStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | leaveEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | } else { |
| | | // 上午or下午总时长 |
| | | leaveDuration += getDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance, day); |
| | | } |
| | | } |
| | | for (AttendanceLeave attendanceLeave : attendanceLeaveList) { |
| | | // attendDate不等于null 说明是考勤信息按钮 |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 上午总时长、下午总时长 |
| | | leaveStartDuration += getStartDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | leaveEndDuration += getEndDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | //调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, leaveStartDuration, leaveEndDuration); |
| | | } else { |
| | | // 上午or下午总时长 |
| | | leaveDuration += getDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance, day); |
| | | //调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(leaveDuration, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, null, null); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改考勤记录打卡状态 |
| | | * |
| | | * @param attendance |
| | | * @param type |
| | | */ |
| | | public void updateAttendanceRecord(Double duration, NewAttendance attendance, String type, Boolean day, Double stDuration, Double enDuration) { |
| | | // 上午排班开始时间到排班午休开始时间的时长 |
| | | Integer workMorningTime = calculateTimes(attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime()); |
| | | Double result = Double.valueOf(new BigDecimal((float) workMorningTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | // 上午实际打卡时间到排班午休开始时间的时长 |
| | | Double result1 = new Double(0.00); |
| | | if (ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && attendance.getActualWorkStartTime().compareTo(attendance.getRosteringLunchStartTime()) <= 0) { |
| | | Integer actualTime = calculateTimes(attendance.getActualWorkStartTime().toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime()); |
| | | result1 = Double.valueOf(new BigDecimal((float) actualTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | // 下午休排班结束时间到下午排班结束时间的时长 |
| | | Integer workNoonTime = calculateTimes(attendance.getRosteringLunchEndTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | Double noonResult = Double.valueOf(new BigDecimal((float) workNoonTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | // 下午排班午休结束时间到下班打卡的实际时间的时长 |
| | | Double noonResult1 = new Double(0.00); |
| | | if (ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && attendance.getActualWorkEndTime().compareTo(attendance.getRosteringLunchEndTime()) >= 0) { |
| | | Integer actualTime = calculateTimes(attendance.getRosteringLunchEndTime().toLocalDateTime(), attendance.getActualWorkEndTime().toLocalDateTime()); |
| | | noonResult1 = Double.valueOf(new BigDecimal((float) actualTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | // 没打卡的情况下,修改考勤打卡状态 |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)) { |
| | | // duration为null说明是考勤信息按钮 |
| | | if (ObjectUtils.isEmpty(duration)) { |
| | | if (stDuration > 0 && enDuration == 0) { |
| | | setAttendance(stDuration, null, result, null, attendance, type); |
| | | } else if (enDuration > 0 && stDuration == 0) { |
| | | setAttendance(null, enDuration, null, noonResult, attendance, type); |
| | | } else { |
| | | setAttendance(stDuration, null, result, null, attendance, type); |
| | | setAttendance(null, enDuration, null, noonResult, attendance, type); |
| | | } |
| | | } else { |
| | | // 上午 |
| | | if (day) { |
| | | // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 |
| | | if (duration >= result) { |
| | | attendance.setStartClockResults(type); |
| | | attendance.setStartLocationResults(null); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } else { |
| | | // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 |
| | | if (duration >= noonResult) { |
| | | attendance.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | // duration为null说明是考勤信息按钮 |
| | | if (ObjectUtils.isEmpty(duration)) { |
| | | if (stDuration > 0 && enDuration == 0) { |
| | | setAttendanceStart(stDuration, null, result1, result, null, attendance, type); |
| | | } else if (enDuration > 0 && stDuration == 0) { |
| | | setAttendanceStart(null, enDuration, noonResult1, null, noonResult, attendance, type); |
| | | } else { |
| | | setAttendanceStart(stDuration, null, result1, result, null, attendance, type); |
| | | setAttendanceStart(null, enDuration, noonResult1, null, noonResult, attendance, type); |
| | | } |
| | | } else { |
| | | //打卡的情况,修改考勤状态 |
| | | if (day) { |
| | | if ((duration + result1) >= result) { |
| | | attendance.setStartClockResults(type); |
| | | attendance.setStartLocationResults(null); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } else { |
| | | if ((duration + noonResult1) >= noonResult) { |
| | | attendance.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询用户 |
| | | */ |
| | | public List<User> getUserList() { |
| | | List<User> userList = userRepository.findAllByEnabled(true); |
| | | return userList; |
| | | } |
| | | |
| | | /** |
| | | * 考勤状态 |
| | | * |
| | | * @param sysRostering |
| | | * @param timestamp |
| | | * @param type |
| | | * @return |
| | | */ |
| | | public String checkResult(SysRostering sysRostering, Timestamp timestamp, Integer type) { |
| | | String result = ObjectUtil.isEmpty(timestamp) ? Constant.ATTENDANCE_STATE_NOTSIGNED : Constant.ATTENDANCE_STATE_NORMAL; |
| | | if (type.equals(1)) { |
| | | if (timestamp.toLocalDateTime().toLocalTime().isAfter(sysRostering.getWorkStartTime())) { |
| | | result = Constant.ATTENDANCE_START_LATE; |
| | | } |
| | | } else { |
| | | if (timestamp.toLocalDateTime().toLocalTime().isBefore(sysRostering.getWorkEndTime())) { |
| | | result = Constant.ATTENDANCE_START_EARLY; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 判断返回位置状态 |
| | | * |
| | | * @param exceptionType |
| | | * @return |
| | | */ |
| | | public String setLocationResults(String exceptionType) { |
| | | String result = ""; |
| | | if (StringUtils.isBlank(exceptionType)) { |
| | | result = Constant.LOCATION_RESULTS_NORMAL; |
| | | } else if (exceptionType.contains("地点异常")) { |
| | | result = Constant.LOCATION_RESULTS_OUTSIDE; |
| | | } else if (exceptionType.contains("未打卡")) { |
| | | result = Constant.LOCATION_RESULTS_NOTSIGNED; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 验证是否有通过的补卡记录 |
| | | * |
| | | * @param userId |
| | | * @param st |
| | | * @param checkTime |
| | | * @return |
| | | */ |
| | | public Boolean getCardSupplement(Long userId, String st, Timestamp checkTime) { |
| | | if (ObjectUtils.isNotEmpty(checkTime)) { |
| | | // 查询补卡记录 |
| | | AttendanceCardreplacement attendanceCardreplacement = attendanceCardreplacementRepository.findByUserIdAndTime(userId, checkTime); |
| | | if (ObjectUtils.isNotEmpty(attendanceCardreplacement) && st.equals(Constant.ATTENDANCE_STATE_NORMAL)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 没打卡情况(考勤按钮) |
| | | * |
| | | * @param sDuration |
| | | * @param eDuration |
| | | * @param result |
| | | * @param noonResult |
| | | * @param attendance |
| | | * @param type |
| | | */ |
| | | public void setAttendance(Double sDuration, Double eDuration, Double result, Double noonResult, NewAttendance attendance, String type) { |
| | | if (ObjectUtils.isEmpty(eDuration) && ObjectUtils.isEmpty(noonResult)) { |
| | | // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 |
| | | if (sDuration >= result) { |
| | | attendance.setStartClockResults(type); |
| | | attendance.setStartLocationResults(null); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } |
| | | if (ObjectUtils.isEmpty(sDuration) && ObjectUtils.isEmpty(result)) { |
| | | // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 |
| | | if (eDuration >= noonResult) { |
| | | attendance.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 打卡情况(考勤按钮) |
| | | * |
| | | * @param sDuration |
| | | * @param eDuration |
| | | * @param result |
| | | * @param noonResult |
| | | * @param attendance |
| | | * @param type |
| | | */ |
| | | public void setAttendanceStart(Double sDuration, Double eDuration, Double result1, Double result, Double noonResult, NewAttendance attendance, String type) { |
| | | if (ObjectUtils.isEmpty(eDuration) && sDuration > 0) { |
| | | if ((sDuration + result1) >= result) { |
| | | attendance.setStartClockResults(type); |
| | | attendance.setStartLocationResults(null); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } |
| | | if (ObjectUtils.isEmpty(sDuration) && eDuration > 0) { |
| | | if ((eDuration + result1) >= noonResult) { |
| | | attendance.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计算时间差 |
| | | * |
| | | * @param start |
| | | * @param end |
| | | * @return |
| | | */ |
| | | public Integer calculateTimes(LocalDateTime start, LocalDateTime end) { |
| | | Integer time = 0; |
| | | Duration duration = null; |
| | | duration = Duration.between(start, start.toLocalDate().atTime(end.toLocalTime())); |
| | | Long StartSeconds = duration.getSeconds(); |
| | | time += StartSeconds.intValue(); |
| | | return time; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取上午/下午时长(请假、出差、外出) |
| | | * |
| | | * @param startDate |
| | | * @param endDate |
| | | * @param attendance |
| | | * @return |
| | | */ |
| | | public Double getDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance, Boolean day) { |
| | | Double duration = new Double(0.00); |
| | | // 上午总时长 |
| | | if (day) { |
| | | if (startDate.toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) { |
| | | Integer leaveSTime = calculateTimes(startDate.toLocalDateTime(), endDate.toLocalDateTime()); |
| | | duration += Double.valueOf(new BigDecimal((float) leaveSTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | if (startDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0 && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0 || |
| | | startDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0 && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) > 0 && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) <= 0) { |
| | | Integer leaveSTime = calculateTimes(startDate.toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime()); |
| | | duration += Double.valueOf(new BigDecimal((float) leaveSTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | } else { |
| | | // 下午总时长 |
| | | if (startDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0 && endDate.toLocalDateTime().compareTo(attendance.getRosteringWorkEndTime().toLocalDateTime()) <= 0) { |
| | | Integer leaveETime = calculateTimes(startDate.toLocalDateTime(), endDate.toLocalDateTime()); |
| | | duration += Double.valueOf(new BigDecimal((float) leaveETime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | if (startDate.toLocalDateTime().isBefore(attendance.getRosteringLunchEndTime().toLocalDateTime()) && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0) { |
| | | Integer leaveETime = calculateTimes(attendance.getRosteringLunchEndTime().toLocalDateTime(), endDate.toLocalDateTime()); |
| | | duration += Double.valueOf(new BigDecimal((float) leaveETime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | } |
| | | return duration; |
| | | } |
| | | |
| | | public Double getStartDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance) { |
| | | Double duration = new Double(0.00); |
| | | // 上午总时长 |
| | | if (startDate.toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) { |
| | | Integer leaveSTime = calculateTimes(startDate.toLocalDateTime(), endDate.toLocalDateTime()); |
| | | duration += Double.valueOf(new BigDecimal((float) leaveSTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | if (startDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0 && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0 || |
| | | startDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0 && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) > 0 && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) <= 0) { |
| | | Integer leaveSTime = calculateTimes(startDate.toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime()); |
| | | duration += Double.valueOf(new BigDecimal((float) leaveSTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | return duration; |
| | | } |
| | | |
| | | public Double getEndDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance) { |
| | | Double duration = new Double(0.00); |
| | | // 下午总时长 |
| | | if (startDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0) { |
| | | Integer leaveETime = calculateTimes(startDate.toLocalDateTime(), endDate.toLocalDateTime()); |
| | | duration += Double.valueOf(new BigDecimal((float) leaveETime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | if (startDate.toLocalDateTime().isBefore(attendance.getRosteringLunchEndTime().toLocalDateTime()) && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0) { |
| | | Integer leaveETime = calculateTimes(attendance.getRosteringLunchEndTime().toLocalDateTime(), endDate.toLocalDateTime()); |
| | | duration += Double.valueOf(new BigDecimal((float) leaveETime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | return duration; |
| | | } |
| | | } |
| New file |
| | |
| | | package me.zhengjie.modules.quartz.task; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | @Async |
| | | public class OpenApiWeComMethod { |
| | | private final WeComServiceImpl weComService; |
| | | |
| | | /** |
| | | * 凌晨0点执行,新增用户考勤信息 |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | public void getWeComAttendanceList() throws Exception { |
| | | // 凌晨0点执行,新增用户考勤信息 |
| | | weComService.getWeComAttendanceList(null, null); |
| | | } |
| | | |
| | | /** |
| | | * 中午12点30执行,更新早打卡情况 |
| | | */ |
| | | public void getWeComAttendanceListOfNoon() throws Exception { |
| | | // 中午12点30执行,更新早打卡情况 |
| | | weComService.getWeComAttendanceListOfNoon(null,null); |
| | | } |
| | | |
| | | /** |
| | | * 凌晨02:30执行,更新晚打卡情况 |
| | | */ |
| | | public void getWeComAttendanceListOfNight() throws Exception { |
| | | // 凌晨02:30执行,更新晚打卡情况 |
| | | weComService.getWeComAttendanceListOfNight(null,null); |
| | | } |
| | | } |
| | |
| | | @ApiModelProperty(value = "实习时间(数字)") |
| | | private Integer internshipTime; |
| | | |
| | | @Column(name = "`we_com_id`") |
| | | @ApiModelProperty(value = "企微ID") |
| | | private String weComId; |
| | | |
| | | @Override |
| | | public boolean equals(Object o) { |
| | | if (this == o) { |
| | |
| | | // 魏传栋 - 终 |
| | | |
| | | private Integer internshipTime; |
| | | |
| | | private String weComId; |
| | | } |
| | |
| | | user.setBirthday(resources.getBirthday());
|
| | | user.setAddress(resources.getAddress());
|
| | | user.setDingding(resources.getDingding());
|
| | | user.setWeComId(resources.getWeComId());
|
| | | user.setSysRostering(resources.getSysRostering());
|
| | | user.setLevelId(resources.getLevelId());
|
| | | // 临时新用户级别ID
|
| | |
| | | #密码加密传输,前端公钥加密,后端私钥解密
|
| | | rsa:
|
| | | private_key: MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A== |
| | |
|
| | | weCom:
|
| | | # 企业ID
|
| | | corpid: wwc0fd49735bfcf0ad
|
| | | # 打卡应用凭证
|
| | | attendanceCorpsecret: 7bPFOunTi9T_TibmacMjzVsaIBEyamSbY2KqQnG1W0E
|
| | |
|
| | | wx:
|
| | | cp:
|
| | | # 企业ID
|
| | | corp-id: wwc0fd49735bfcf0ad
|
| | | # 应用AgentId
|
| | | agent-id: 1000005
|
| | | # 应用凭证
|
| | | corp-secret: nDCq9I6tSWAP-l2lbvgtK8_V5l1DpqFq88Gf67TK_-I
|
| | | config-storage:
|
| | | type: redistemplate
|
| | | redis:
|
| | | database: ${REDIS_DB:0}
|
| | | host: ${REDIS_HOST:localhost}
|
| | | port: ${REDIS_PORT:6379}
|
| | | password: ${REDIS_PWD:}
|
| | | timeout: 5000
|
| | |
|
| New file |
| | |
| | | import request from '@/utils/request' |
| | | |
| | | export function getAll(params) { |
| | | return request({ |
| | | url: 'api/newAttendance/all', |
| | | method: 'get', |
| | | params |
| | | }) |
| | | } |
| | | |
| | | export function add(data) { |
| | | return request({ |
| | | url: 'api/newAttendance', |
| | | method: 'post', |
| | | data |
| | | }) |
| | | } |
| | | |
| | | export function del(ids) { |
| | | return request({ |
| | | url: 'api/newAttendance/', |
| | | method: 'delete', |
| | | data: ids |
| | | }) |
| | | } |
| | | |
| | | export function edit(data) { |
| | | return request({ |
| | | url: 'api/newAttendance', |
| | | method: 'put', |
| | | data |
| | | }) |
| | | } |
| | | |
| | | export function queryAttendanceHours(params) { |
| | | return request({ |
| | | url: 'api/newAttendance/queryAttendanceHours', |
| | | method: 'get', |
| | | params |
| | | }) |
| | | } |
| | | |
| | | export function attendanceHours(params) { |
| | | return request({ |
| | | url: 'api/newAttendance/attendanceHours', |
| | | method: 'get', |
| | | params |
| | | }) |
| | | } |
| | | |
| | | export function getUserMakeUpCard(data) { |
| | | return request({ |
| | | url: 'api/newAttendance/getUserMakeUpCard', |
| | | method: 'post', |
| | | data |
| | | }) |
| | | } |
| | | |
| | | export function addAttendanceInfo(data) { |
| | | return request({ |
| | | url: 'api/newAttendance/addAttendanceInfo', |
| | | method: 'post', |
| | | data |
| | | }) |
| | | } |
| | | |
| | | export default { add, edit, del, getAll, attendanceHours, getUserMakeUpCard, addAttendanceInfo, queryAttendanceHours } |
| New file |
| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <!--工具栏--> |
| | | <div class="head-container"> |
| | | <div> |
| | | <el-select v-model="query.userId" filterable clearable placeholder="所属员工" style="width: 185px;" 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" |
| | | type="daterange" |
| | | clearable |
| | | class="filter-item" |
| | | value-format="yyyy-MM-dd" |
| | | placeholder="请选择考勤日期" |
| | | range-separator=" ~ " |
| | | start-placeholder="开始日期" |
| | | end-placeholder="结束日期" |
| | | style="width: 285px;" |
| | | /> |
| | | <el-select v-model="query.startLocationResults" filterable clearable placeholder="开始位置结果" style="width: 185px;" 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: 185px;" 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: 185px;" 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: 185px;" 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-button |
| | | slot="right" |
| | | size="mini" |
| | | type="primary" |
| | | icon="el-icon-timer" |
| | | class="filter-item" |
| | | :disabled="crud.selections.length !== 1" |
| | | @click="makeUpCardOnDuty(crud.selections[0],1)" |
| | | >上班补卡 |
| | | </el-button> |
| | | <el-button |
| | | slot="right" |
| | | size="mini" |
| | | type="primary" |
| | | icon="el-icon-timer" |
| | | class="filter-item" |
| | | :disabled="crud.selections.length !== 1" |
| | | style="margin-left: 4px !important;" |
| | | @click="makeUpCardOnDuty(crud.selections[0],2)" |
| | | >下班补卡 |
| | | </el-button> |
| | | <el-button |
| | | slot="right" |
| | | size="mini" |
| | | type="primary" |
| | | icon="el-icon-suitcase-1" |
| | | class="filter-item" |
| | | :disabled="crud.selections.length == null" |
| | | style="margin-left: 4px !important;" |
| | | @click="toGoOutRequest('goOut')" |
| | | >外出申请 |
| | | </el-button> |
| | | <el-button |
| | | slot="right" |
| | | size="mini" |
| | | type="primary" |
| | | icon="el-icon-timer" |
| | | class="filter-item" |
| | | :disabled="crud.selections.length == null" |
| | | style="margin-left: 4px !important;" |
| | | @click="toGoOutRequest()" |
| | | >出差申请 |
| | | </el-button> |
| | | <el-button |
| | | slot="right" |
| | | size="mini" |
| | | type="primary" |
| | | icon="el-icon-plus" |
| | | class="filter-item" |
| | | :disabled="crud.selections.length == null" |
| | | style="margin-left: 4px !important;" |
| | | @click="toSupplementInfo()" |
| | | >考勤生成 |
| | | </el-button> |
| | | </crudOperation> |
| | | <!--表单组件--> |
| | | <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="140px"> |
| | | <el-form-item label="所属员工" prop="userId"> |
| | | <el-select v-model="form.userId" clearable filterable placeholder="请选择" style="width: 310px;" @change="getRosteTime(form)"> |
| | | <el-option |
| | | v-for="item in users" |
| | | :key="item.id" |
| | | :label="item.nickName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="考勤日期" prop="attendanceDate"> |
| | | <el-date-picker v-model="form.attendanceDate" style="width: 310px;" type="date" placeholder="选择日期" @change="getRosteTime(form)" /> |
| | | </el-form-item> |
| | | <el-form-item label="排班工作开始时间" prop="rosteringWorkStartTime"> |
| | | <el-date-picker |
| | | v-model="form.rosteringWorkStartTime" |
| | | type="datetime" |
| | | placeholder="选择日期时间" |
| | | style="width: 310px;" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | align="right" |
| | | :picker-options="{ |
| | | disabledDate(time) { |
| | | return form.rosteringWorkEndTime ? time.getTime() > new Date(form.rosteringWorkEndTime).getTime() - 8.64e7 : false; |
| | | } |
| | | }" |
| | | :default-time="$store.state.user.user.sysRostering.workStartTime + ':00'" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="实际工作开始时间" prop="actualWorkStartTime"> |
| | | <el-date-picker |
| | | v-model="form.actualWorkStartTime" |
| | | type="datetime" |
| | | placeholder="选择日期时间" |
| | | style="width: 310px;" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | align="right" |
| | | :picker-options="{ |
| | | disabledDate(time) { |
| | | return form.actualWorkEndTime ? time.getTime() > new Date(form.actualWorkEndTime).getTime() - 8.64e7 : false; |
| | | } |
| | | }" |
| | | :default-time="$store.state.user.user.sysRostering.workStartTime + ':00'" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="开始位置结果" prop="startLocationResults"> |
| | | <el-select v-model="form.startLocationResults" style="width: 310px;"> |
| | | <el-option |
| | | v-for="item in dict[lacationResules]" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="开始打卡结果" prop="startClockResults"> |
| | | <el-select v-model="form.startClockResults" style="width: 310px;"> |
| | | <el-option |
| | | v-for="item in dict[attendanceState]" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="排班工作结束时间" prop="rosteringWorkEndTime"> |
| | | <el-date-picker |
| | | v-model="form.rosteringWorkEndTime" |
| | | type="datetime" |
| | | placeholder="选择日期时间" |
| | | style="width: 310px;" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | align="right" |
| | | :picker-options="{ |
| | | disabledDate(time) { |
| | | return form.rosteringWorkStartTime ? time.getTime() < new Date(form.rosteringWorkStartTime).getTime() - 8.64e7 : false; |
| | | } |
| | | }" |
| | | :default-time="$store.state.user.user.sysRostering.workEndTime + ':00'" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="实际工作结束时间" prop="actualWorkEndTime"> |
| | | <el-date-picker |
| | | v-model="form.actualWorkEndTime" |
| | | type="datetime" |
| | | placeholder="选择日期时间" |
| | | style="width: 310px;" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | align="right" |
| | | :picker-options="{ |
| | | disabledDate(time) { |
| | | return form.actualWorkStartTime ? time.getTime() < new Date(form.actualWorkStartTime).getTime() - 8.64e7 : false; |
| | | } |
| | | }" |
| | | :default-time="$store.state.user.user.sysRostering.workEndTime + ':00'" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="结束位置结果" prop="endLocationResults"> |
| | | <el-select v-model="form.endLocationResults" style="width: 310px;"> |
| | | <el-option |
| | | v-for="item in dict[lacationResules]" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="结束打卡结果" prop="endClockResults"> |
| | | <el-select v-model="form.endClockResults" style="width: 310px;"> |
| | | <el-option |
| | | v-for="item in dict[attendanceState]" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="日期类型" prop="dateType"> |
| | | <el-select v-model="form.dateType" style="width: 310px;"> |
| | | <el-option |
| | | v-for="item in dict[dateType]" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="备注"> |
| | | <el-input v-model="form.remarks" type="textarea" rows="3" style="width: 310px;" /> |
| | | </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-dialog :close-on-click-modal="false" :before-close="closeCard" :visible.sync="makeUpCardVisible" :title="makeUpCardTitle" width="500px"> |
| | | <el-form ref="makeUpCardForm" :model="makeUpCardForm" :rules="makeRules" size="small" label-width="80px"> |
| | | <el-form-item label="基准时间"> |
| | | <span>{{ makeUpCardForm.rosterTime }}</span> |
| | | </el-form-item> |
| | | <el-form-item label="补卡时间" prop="cardReplacementTime"> |
| | | <div> |
| | | <label style="margin-right: 5px">日期:</label> |
| | | <span>{{ makeUpCardForm.checkDate }}</span> |
| | | </div> |
| | | <div> |
| | | <label style="margin-right: 5px">时间:</label> |
| | | <el-time-picker |
| | | v-model="makeUpCardForm.cardReplacementTime" |
| | | placeholder="选择时间" |
| | | format="HH:mm:ss" |
| | | value-format="HH:mm:ss" |
| | | style="width: 330px;" |
| | | /> |
| | | </div> |
| | | </el-form-item> |
| | | <el-form-item label="审批人" prop="approvalUserId"> |
| | | <el-select v-model="makeUpCardForm.approvalUserId" clearable filterable placeholder="请选择" style="width: 370px;"> |
| | | <el-option |
| | | v-for="item in approvalUsers" |
| | | :key="item.id" |
| | | :label="item.nickName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="补卡原因"> |
| | | <el-input v-model="makeUpCardForm.cardReplacementReason" type="textarea" rows="3" style="width: 370px;" /> |
| | | </el-form-item> |
| | | <el-form-item label="备注"> |
| | | <el-input v-model="makeUpCardForm.remarks" type="textarea" rows="3" style="width: 370px;" /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button type="text" @click="closeCard">取消</el-button> |
| | | <el-button :loading="makeUpCardLoading" type="primary" @click="submitMakeUpCard">确认</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | <!--外出表单--> |
| | | <el-dialog :close-on-click-modal="false" :before-close="closeCard" :visible.sync="goOutVisible" :title="goOutTitle" width="500px"> |
| | | <el-form ref="goOutForm" :model="goOutForm" :rules="goOutRules" size="small" label-width="80px"> |
| | | <el-form-item label="开始时间" prop="outStartTime"> |
| | | <el-date-picker |
| | | v-model="goOutForm.outStartTime" |
| | | type="datetime" |
| | | placeholder="选择日期时间" |
| | | style="width: 370px;" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | align="right" |
| | | :picker-options="{ |
| | | disabledDate(time) { |
| | | return goOutForm.outEndTime ? time.getTime() > new Date(goOutForm.outEndTime).getTime() - 8.64e7 : false; |
| | | } |
| | | }" |
| | | :default-time="$store.state.user.user.sysRostering.workStartTime + ':00'" |
| | | @change="checkTime('goOut')" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="结束时间" prop="outEndTime"> |
| | | <el-date-picker |
| | | v-model="goOutForm.outEndTime" |
| | | type="datetime" |
| | | placeholder="选择日期时间" |
| | | style="width: 370px;" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | align="right" |
| | | :picker-options="{ |
| | | disabledDate(time) { |
| | | return goOutForm.outStartTime ? time.getTime() < new Date(goOutForm.outStartTime).getTime() - 8.64e7 : false; |
| | | } |
| | | }" |
| | | :default-time="$store.state.user.user.sysRostering.workEndTime + ':00'" |
| | | @change="checkTime('goOut')" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="外出时长" prop="outDuration"> |
| | | <el-input v-model="goOutForm.outDuration" disabled style="width: 370px;"> |
| | | <template slot="append">{{ dict.label[dictLeaveTimeType][goOutForm.durationUnit] }}</template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="外出类型" prop="outOfOfficeType"> |
| | | <el-select v-model="goOutForm.outOfOfficeType" filterable clearable placeholder="请选择" style="width: 370px;"> |
| | | <el-option |
| | | v-for="item in dict[dictGoOutTypr]" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="审批员工" prop="approvalUserId"> |
| | | <el-select v-model="goOutForm.approvalUserId" filterable clearable placeholder="请选择" style="width: 370px;"> |
| | | <el-option |
| | | v-for="item in approvalUsers" |
| | | :key="item.id" |
| | | :label="item.nickName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="外出原因"> |
| | | <el-input v-model="goOutForm.outReason" type="textarea" rows="3" style="width: 370px;" /> |
| | | </el-form-item> |
| | | <el-form-item label="备注"> |
| | | <el-input v-model="goOutForm.remarks" type="textarea" rows="3" style="width: 370px;" /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button type="text" @click="closeCard">取消</el-button> |
| | | <el-button :loading="goSuccessLoading" type="primary" @click="submitGoOut">确认</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | <!--出差表单--> |
| | | <el-dialog :close-on-click-modal="false" :before-close="closeCard" :visible.sync="bussVisible" :title="bussTitle" width="500px"> |
| | | <el-form ref="bussForm" :model="bussForm" :rules="bussRules" size="small" label-width="80px"> |
| | | <el-form-item label="开始日期" prop="travelStartTime"> |
| | | <el-date-picker |
| | | v-model="bussForm.travelStartTime" |
| | | type="date" |
| | | placeholder="选择日期" |
| | | style="width: 370px;" |
| | | value-format="yyyy-MM-dd" |
| | | align="right" |
| | | :picker-options="{ |
| | | disabledDate(time) { |
| | | return bussForm.travelEndTime ? time.getTime() > new Date(bussForm.travelEndTime).getTime() - 8.64e7 : false; |
| | | } |
| | | }" |
| | | @change="checkTime()" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="结束日期" prop="travelEndTime"> |
| | | <el-date-picker |
| | | v-model="bussForm.travelEndTime" |
| | | type="date" |
| | | placeholder="选择日期" |
| | | style="width: 370px;" |
| | | value-format="yyyy-MM-dd" |
| | | align="right" |
| | | :picker-options="{ |
| | | disabledDate(time) { |
| | | return bussForm.travelStartTime ? time.getTime() < new Date(bussForm.travelStartTime).getTime() - 8.64e7 : false; |
| | | } |
| | | }" |
| | | @change="checkTime()" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="出差时长" prop="travelDuration"> |
| | | <el-input v-model="bussForm.travelDuration" disabled style="width: 370px;"> |
| | | <template slot="append">{{ dict.label[dictLeaveTimeType][bussForm.durationUnit] }}</template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="审批员工" prop="approvalUserId"> |
| | | <el-select v-model="bussForm.approvalUserId" filterable clearable placeholder="请选择" style="width: 370px;"> |
| | | <el-option |
| | | v-for="item in approvalUsers" |
| | | :key="item.id" |
| | | :label="item.nickName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="出差原因"> |
| | | <el-input v-model="bussForm.travelReason" type="textarea" rows="3" style="width: 370px;" /> |
| | | </el-form-item> |
| | | <el-form-item label="出发城市"> |
| | | <el-input v-model="bussForm.departureCity" style="width: 370px;" /> |
| | | </el-form-item> |
| | | <el-form-item label="到达城市"> |
| | | <el-input v-model="bussForm.arrivalCity" style="width: 370px;" /> |
| | | </el-form-item> |
| | | <el-form-item label="备注"> |
| | | <el-input v-model="bussForm.remarks" type="textarea" rows="3" style="width: 370px;" /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button type="text" @click="closeCard">取消</el-button> |
| | | <el-button :loading="bussSuccessLoading" type="primary" @click="submitBuss">确认</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | <!--考勤信息补充--> |
| | | <el-dialog :close-on-click-modal="false" :before-close="closeCard" :visible.sync="attendVisible" :title="attendTitle" width="500px"> |
| | | <el-form ref="attform" :model="attform" :rules="attRules" size="small" label-width="80px"> |
| | | <el-form-item label="考勤日期" prop="attendTime"> |
| | | <el-date-picker |
| | | v-model="attform.attendTime" |
| | | type="date" |
| | | placeholder="选择日期" |
| | | style="width: 370px;" |
| | | value-format="yyyy-MM-dd" |
| | | align="right" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="所属员工" prop="userId"> |
| | | <el-select v-model="attform.userId" filterable clearable placeholder="请选择" style="width: 370px;"> |
| | | <el-option |
| | | v-for="item in users1" |
| | | :key="item.id" |
| | | :label="item.nickName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <div class="attCss" style="color: red;">*选择员工则更新选中员工的考勤信息,未选择员工则更新所有员工的考勤信息</div> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button type="text" @click="closeCard">取消</el-button> |
| | | <el-button :loading="attendLoading" type="primary" @click="submitAttendance">确认</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | <!--表格渲染--> |
| | | <el-table ref="table" v-loading="crud.loading" :data="crud.data" row-key="id" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler"> |
| | | <el-table-column type="selection" width="55" /> |
| | | <el-table-column prop="userName" label="所属员工" fixed="left" width="100" show-overflow-tooltip> |
| | | <template slot-scope="scope"> |
| | | <el-tag>{{ scope.row.userName }}</el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="attendanceDate" label="考勤日期" fixed="left" width="100" show-overflow-tooltip> |
| | | <template slot-scope="scope"> |
| | | {{ crud.toDate(scope.row.attendanceDate) }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="rosteringWorkStartTime" min-width="140" label="排班工作开始时间" show-overflow-tooltip /> |
| | | <el-table-column prop="actualWorkStartTime" min-width="140" label="实际工作开始时间" show-overflow-tooltip /> |
| | | <el-table-column prop="startLocationResults" min-width="100" label="开始位置结果" show-overflow-tooltip> |
| | | <template slot-scope="scope"> |
| | | <el-tag v-if="scope.row.startLocationResults === dictlocationResultsNormal" type="success">{{ dict.label[lacationResules][scope.row.startLocationResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startLocationResults === dictlocationResultsOutside" type="warning">{{ dict.label[lacationResules][scope.row.startLocationResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startLocationResults === dictlocationResultsNotSigned" type="danger">{{ dict.label[lacationResules][scope.row.startLocationResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startLocationResults === dictlocationResultsRest" type="warning">{{ dict.label[lacationResules][scope.row.startLocationResults] }}</el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="startClockResults" min-width="100" label="开始打卡结果" show-overflow-tooltip> |
| | | <template slot-scope="scope"> |
| | | <el-tag v-if="scope.row.startClockResults === dictAttendanceStateWaitFor" type="warning">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startClockResults === dictAttendanceStateNormal" type="success">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startClockResults === dictAttendanceStateNotSigned" type="danger">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startClockResults === dictAttendanceStateGoOut" type="success">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startClockResults === dictAttendanceStateBusiness" type="success">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startClockResults === dictAttendanceStateLeave" type="success">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startClockResults === dictAttendanceStateRest" type="warning">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startClockResults === dictEndanceStateLackOfTime" type="danger">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.startClockResults === dictStartLate" type="warning">{{ dict.label[attendanceState][scope.row.startClockResults] }}</el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="rosteringWorkEndTime" min-width="140" label="排班工作结束时间" show-overflow-tooltip /> |
| | | <el-table-column prop="actualWorkEndTime" min-width="140" label="实际工作结束时间" show-overflow-tooltip /> |
| | | <el-table-column prop="endLocationResults" min-width="100" label="结束位置结果" show-overflow-tooltip> |
| | | <template slot-scope="scope"> |
| | | <el-tag v-if="scope.row.endLocationResults === dictlocationResultsNormal" type="success">{{ dict.label[lacationResules][scope.row.endLocationResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endLocationResults === dictlocationResultsOutside" type="warning">{{ dict.label[lacationResules][scope.row.endLocationResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endLocationResults === dictlocationResultsNotSigned" type="danger">{{ dict.label[lacationResules][scope.row.endLocationResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endLocationResults === dictlocationResultsRest" type="warning">{{ dict.label[lacationResules][scope.row.endLocationResults] }}</el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="endClockResults" min-width="100" label="结束打卡结果" show-overflow-tooltip> |
| | | <template slot-scope="scope"> |
| | | <el-tag v-if="scope.row.endClockResults === dictAttendanceStateWaitFor" type="warning">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endClockResults === dictAttendanceStateNormal" type="success">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endClockResults === dictAttendanceStateNotSigned" type="danger">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endClockResults === dictAttendanceStateGoOut" type="success">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endClockResults === dictAttendanceStateBusiness" type="success">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endClockResults === dictAttendanceStateLeave" type="success">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endClockResults === dictAttendanceStateRest" type="warning">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endClockResults === dictEndanceStateLackOfTime" type="danger">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | <el-tag v-if="scope.row.endClockResults === dictStartEarly" type="warning">{{ dict.label[attendanceState][scope.row.endClockResults] }}</el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="dateType" min-width="80" label="日期类型" show-overflow-tooltip> |
| | | <template slot-scope="scope"> |
| | | <el-tag>{{ dict.label[dateType][scope.row.dateType] }}</el-tag> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="remarks" label="备注" min-width="140" show-overflow-tooltip /> |
| | | <el-table-column prop="createTime" label="创建时间" min-width="140" show-overflow-tooltip /> |
| | | <el-table-column v-if="checkPer(['admin','newAttendance:edit','newAttendance:del'])" label="操作" width="150px" align="center" fixed="right"> |
| | | <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/newAttendance' |
| | | import crudAttendanceCardreplacement from '@/api/attendance/attendanceCardreplacement' |
| | | import crudAttendanceGoOut from '@/api/attendance/attendanceGoOut' |
| | | import crudAttendanceBusinessTravel from '@/api/attendance/attendanceBusinessTravel' |
| | | import crudUser 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: 'NewAttendance', |
| | | components: { pagination, crudOperation, rrOperation, udOperation }, |
| | | mixins: [presenter(), header(), form(defaultForm), crud()], |
| | | cruds() { |
| | | return CRUD({ title: '考勤记录(新)', url: 'api/newAttendance', idField: 'id', sort: 'attendanceDate,desc', crudMethod: { ...crudAttendance }}) |
| | | }, |
| | | // 数据字典 |
| | | dicts: [constant.ATTENDANCE_STATE, constant.DATE_TYPE, constant.LOCATION_RESULTS, constant.CARD_REPLACEMENT_DIFFERENTIATION, constant.CARD_APPROVE_STATUS, constant.LEAVE_TIME_TYPE, constant.GO_OUT_TYPE], |
| | | data() { |
| | | return { |
| | | permission: { |
| | | add: ['admin', 'newAttendance:add'], |
| | | edit: ['admin', 'newAttendance:edit'], |
| | | del: ['admin', 'newAttendance:del'], |
| | | download: ['admin', 'newAttendance:download'], |
| | | addAttendanceInfo: ['admin', 'newAttendance:addAttendanceInfo'] |
| | | }, |
| | | rules: { |
| | | userId: [ |
| | | { required: true, message: '所属员工不能为空', trigger: 'change' } |
| | | ], |
| | | attendanceDate: [ |
| | | { required: true, message: '考勤日期不能为空', trigger: 'blur' } |
| | | ], |
| | | rosteringWorkStartTime: [ |
| | | { required: true, message: '排班工作开始时间不能为空', trigger: 'blur' } |
| | | ], |
| | | rosteringWorkEndTime: [ |
| | | { required: true, message: '排班工作结束时间不能为空', trigger: 'blur' } |
| | | ], |
| | | dateType: [ |
| | | { required: true, message: '日期类型不能为空', trigger: 'change' } |
| | | ] |
| | | }, |
| | | makeRules: { |
| | | cardReplacementTime: [ |
| | | { required: true, message: '补卡时间不能为空', trigger: 'change' } |
| | | ], |
| | | approvalUserId: [ |
| | | { required: true, message: '审批人不能为空', trigger: 'change' } |
| | | ] |
| | | }, |
| | | goOutRules: { |
| | | outStartTime: [ |
| | | { required: true, message: '开始时间不能为空', trigger: 'blur' } |
| | | ], |
| | | outEndTime: [ |
| | | { required: true, message: '结束时间不能为空', trigger: 'blur' } |
| | | ], |
| | | outDuration: [ |
| | | { required: true, message: '外出时长不能为空', trigger: 'change' } |
| | | ], |
| | | outOfOfficeType: [ |
| | | { required: true, message: '外出类型不能为空', trigger: 'change' } |
| | | ], |
| | | approvalUserId: [ |
| | | { required: true, message: '审批人不能为空', trigger: 'change' } |
| | | ] |
| | | }, |
| | | bussRules: { |
| | | travelStartTime: [ |
| | | { required: true, message: '开始时间不能为空', trigger: 'blur' } |
| | | ], |
| | | travelEndTime: [ |
| | | { required: true, message: '结束时间不能为空', trigger: 'blur' } |
| | | ], |
| | | travelDuration: [ |
| | | { required: true, message: '出差时长不能为空', trigger: 'change' } |
| | | ], |
| | | approvalUserId: [ |
| | | { required: true, message: '审批人不能为空', trigger: 'change' } |
| | | ] |
| | | }, |
| | | attRules: { |
| | | attendTime: [ |
| | | { required: true, message: '考勤日期不能为空', trigger: 'change' } |
| | | ] |
| | | }, |
| | | attendanceState: constant.ATTENDANCE_STATE, |
| | | lacationResules: constant.LOCATION_RESULTS, |
| | | dateType: constant.DATE_TYPE, |
| | | dictlocationResultsNormal: constant.LOCATION_RESULTS_NORMAL, |
| | | dictlocationResultsOutside: constant.LOCATION_RESULTS_OUTSIDE, |
| | | dictlocationResultsNotSigned: constant.LOCATION_RESULTS_NOTSIGNED, |
| | | dictlocationResultsRest: constant.LOCATION_RESULTS_REST, |
| | | dictAttendanceStateWaitFor: constant.ATTENDANCE_STATE_WAITFOR, |
| | | dictAttendanceStateNormal: constant.ATTENDANCE_STATE_NORMAL, |
| | | dictAttendanceStateNotSigned: constant.ATTENDANCE_STATE_NOTSIGNED, |
| | | dictAttendanceStateGoOut: constant.ATTENDANCE_STATE_GOOUT, |
| | | dictAttendanceStateBusiness: constant.ATTENDANCE_STATE_BUSINESS, |
| | | dictAttendanceStateLeave: constant.ATTENDANCE_STATE_LEAVE, |
| | | dictAttendanceStateRest: constant.ATTENDANCE_STATE_REST, |
| | | dictEndanceStateLackOfTime: constant.ATTENDANCE_STATE_LACK_OF_TIME, |
| | | dictStartEarly: constant.ATTENDANCE_STATE_EARLY, |
| | | dictStartLate: constant.ATTENDANCE_STATE_LATE, |
| | | users: [], |
| | | users1: [], |
| | | approvalUsers: [], |
| | | makeUpCardVisible: false, |
| | | makeUpCardLoading: false, |
| | | makeUpCardTitle: '', |
| | | makeUpCardForm: { |
| | | id: null, |
| | | userId: null, |
| | | approvalUserId: null, |
| | | cardReplacementTime: null, |
| | | cardReplacementReason: null, |
| | | approvalStatus: null, |
| | | approvalDescription: null, |
| | | cardReplacementDistinguish: null, |
| | | remarks: null, |
| | | rosterTime: null, |
| | | timeResult: null, |
| | | checkDate: null |
| | | }, |
| | | goOutForm: { |
| | | id: null, |
| | | userId: null, |
| | | approvalUserId: null, |
| | | outStartTime: null, |
| | | outEndTime: null, |
| | | outDuration: null, |
| | | outReason: null, |
| | | remarks: null |
| | | }, |
| | | bussForm: { |
| | | id: null, |
| | | userId: null, |
| | | approvalUserId: null, |
| | | travelStartTime: null, |
| | | travelEndTime: null, |
| | | travelDuration: null, |
| | | travelReason: null, |
| | | departureCity: null, |
| | | arrivalCity: null, |
| | | remarks: null |
| | | }, |
| | | attform: { |
| | | attendTime: null, |
| | | userId: null |
| | | }, |
| | | dictCardReplacementGoOn: constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, |
| | | dictCardReplacementOffOn: constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, |
| | | dictCardApproveStatusReviewed: constant.CARD_APPROVE_STATUS_REVIEWED, |
| | | goOutVisible: false, |
| | | goSuccessLoading: false, |
| | | dictLeaveTimeType: constant.LEAVE_TIME_TYPE, |
| | | dictGoOutTypr: constant.GO_OUT_TYPE, |
| | | goOutTitle: '外出申请', |
| | | dictLeaveTimeTypeHour: constant.LEAVE_TIME_TYPE_HOUR, |
| | | dictLeaveTimeTypeDay: constant.LEAVE_TIME_TYPE_DAY, |
| | | bussVisible: false, |
| | | bussSuccessLoading: false, |
| | | bussTitle: '出差申请', |
| | | attendVisible: false, |
| | | attendLoading: false, |
| | | attendTitle: '考勤信息补充' } |
| | | }, |
| | | methods: { |
| | | // 钩子:在获取表格数据之前执行,false 则代表不获取数据 |
| | | [CRUD.HOOK.beforeRefresh]() { |
| | | this.getUsers() |
| | | this.getUsers1() |
| | | this.getApprovalUsers() |
| | | return true |
| | | }, |
| | | // 查询员工 |
| | | getUsers() { |
| | | crudUser.getAll().then(res => { |
| | | this.users = res |
| | | }) |
| | | }, |
| | | // 查询员工 |
| | | getUsers1() { |
| | | crudUser.getUserInfose().then(res => { |
| | | this.users1 = res |
| | | }) |
| | | }, |
| | | // 查询审核人 |
| | | getApprovalUsers() { |
| | | crudUser.getApprovalUsers().then(res => { |
| | | this.approvalUsers = res |
| | | }) |
| | | }, |
| | | // 获取表格上下班排班时间 |
| | | getRosteTime(data) { |
| | | if (data.userId !== null && data.attendanceDate !== null) { |
| | | // 根据用户id查询排班时间 |
| | | crudUser.getAll({ id: data.userId }).then(res => { |
| | | this.form.rosteringWorkStartTime = new Date(this.crud.toDate(data.attendanceDate) + ' ' + res[0].sysRostering.workStartTime) |
| | | this.form.rosteringWorkEndTime = new Date(this.crud.toDate(data.attendanceDate) + ' ' + res[0].sysRostering.workEndTime) |
| | | }) |
| | | } |
| | | }, |
| | | // 补卡页面 |
| | | makeUpCardOnDuty(data, Number) { |
| | | this.makeUpCardForm.checkDate = this.crud.toDate(data.attendanceDate) |
| | | this.makeUpCardForm.userId = data.userId |
| | | this.makeUpCardForm.approvalStatus = this.dictCardApproveStatusReviewed |
| | | // 除了超管总经理只能补自己的卡 |
| | | crudAttendance.getUserMakeUpCard(this.makeUpCardForm.userId).then(res => { |
| | | // 判断上班打卡状态,给提示 |
| | | if (Number === 1) { |
| | | if (data.startLocationResults !== null && data.startLocationResults === this.dictlocationResultsNotSigned) { |
| | | this.makeUpCardTitle = '上班补卡' |
| | | this.makeUpCardForm.timeResult = data.startClockResults |
| | | this.makeUpCardForm.rosterTime = data.rosteringWorkStartTime |
| | | this.makeUpCardForm.cardReplacementTime = data.rosteringWorkStartTime.substring(11, 19) |
| | | this.makeUpCardForm.cardReplacementDistinguish = this.dictCardReplacementGoOn |
| | | this.makeUpCardVisible = true |
| | | } else { |
| | | this.crud.notify('上班无需补卡', CRUD.NOTIFICATION_TYPE.ERROR) |
| | | } |
| | | } |
| | | // 判断下班打卡状态,给提示 |
| | | if (Number === 2) { |
| | | if (data.endLocationResults !== null && data.endLocationResults === this.dictlocationResultsNotSigned) { |
| | | this.makeUpCardTitle = '下班补卡' |
| | | this.makeUpCardForm.timeResult = data.endClockResults |
| | | this.makeUpCardForm.rosterTime = data.rosteringWorkEndTime |
| | | this.makeUpCardForm.cardReplacementTime = data.rosteringWorkEndTime.substring(11, 19) |
| | | this.makeUpCardForm.cardReplacementDistinguish = this.dictCardReplacementOffOn |
| | | this.makeUpCardVisible = true |
| | | } else { |
| | | this.crud.notify('下班无需补卡', CRUD.NOTIFICATION_TYPE.ERROR) |
| | | } |
| | | } |
| | | }).catch(() => { |
| | | }) |
| | | }, |
| | | // 补卡提交 |
| | | submitMakeUpCard() { |
| | | this.$refs['makeUpCardForm'].validate(valid => { |
| | | if (!valid) { |
| | | return |
| | | } |
| | | this.makeUpCardLoading = true |
| | | this.makeUpCardForm.cardReplacementTime = this.makeUpCardForm.checkDate + ' ' + this.makeUpCardForm.cardReplacementTime |
| | | crudAttendanceCardreplacement.add(this.makeUpCardForm).then(res => { |
| | | this.makeUpCardVisible = false |
| | | this.makeUpCardLoading = false |
| | | this.crud.notify('补卡提交成功', CRUD.NOTIFICATION_TYPE.SUCCESS) |
| | | if (this.$refs['makeUpCardForm']) { |
| | | this.$refs['makeUpCardForm'].resetFields() |
| | | } |
| | | }).catch(() => { |
| | | this.makeUpCardLoading = false |
| | | }) |
| | | }) |
| | | }, |
| | | // 外出和出差打开画面 |
| | | toGoOutRequest(data) { |
| | | if (data === 'goOut') { |
| | | this.goOutVisible = true |
| | | this.goOutForm.durationUnit = this.dictLeaveTimeTypeHour |
| | | } else { |
| | | this.bussVisible = true |
| | | this.bussForm.durationUnit = this.dictLeaveTimeTypeDay |
| | | } |
| | | }, |
| | | // 计算时长 |
| | | checkTime(data) { |
| | | if (data === 'goOut') { |
| | | const params = JSON.stringify({ |
| | | 'outStartTime': this.goOutForm.outStartTime, |
| | | 'outEndTime': this.goOutForm.outEndTime |
| | | }) |
| | | crudAttendanceGoOut.getRemainingTime(params).then(res => { |
| | | this.goOutForm.outDuration = res |
| | | }) |
| | | } else { |
| | | const params = JSON.stringify({ |
| | | 'travelStartTime': this.bussForm.travelStartTime, |
| | | 'travelEndTime': this.bussForm.travelEndTime |
| | | }) |
| | | crudAttendanceBusinessTravel.getRemainingTime(params).then(res => { |
| | | this.bussForm.travelDuration = res |
| | | }) |
| | | } |
| | | }, |
| | | // 外出提交 |
| | | submitGoOut() { |
| | | this.$refs['goOutForm'].validate(valid => { |
| | | if (!valid) { |
| | | return |
| | | } |
| | | this.goSuccessLoading = true |
| | | crudAttendanceGoOut.add(this.goOutForm).then(res => { |
| | | this.goOutVisible = false |
| | | this.goSuccessLoading = false |
| | | this.crud.notify('外出提交成功', CRUD.NOTIFICATION_TYPE.SUCCESS) |
| | | if (this.$refs['goOutForm']) { |
| | | this.$refs['goOutForm'].resetFields() |
| | | } |
| | | }).catch(() => { |
| | | this.goSuccessLoading = false |
| | | }) |
| | | }) |
| | | }, |
| | | // 出差提交 |
| | | submitBuss() { |
| | | this.$refs['bussForm'].validate(valid => { |
| | | if (!valid) { |
| | | return |
| | | } |
| | | this.bussSuccessLoading = true |
| | | crudAttendanceBusinessTravel.add(this.bussForm).then(res => { |
| | | this.bussVisible = false |
| | | this.bussSuccessLoading = false |
| | | this.crud.notify('出差提交成功', CRUD.NOTIFICATION_TYPE.SUCCESS) |
| | | if (this.$refs['bussForm']) { |
| | | this.$refs['bussForm'].resetFields() |
| | | } |
| | | }).catch(() => { |
| | | this.bussSuccessLoading = false |
| | | }) |
| | | }) |
| | | }, |
| | | // 考勤信息补充画面打开 |
| | | toSupplementInfo() { |
| | | this.attendVisible = true |
| | | }, |
| | | // 考勤信息提交 |
| | | submitAttendance() { |
| | | this.$refs['attform'].validate(valid => { |
| | | if (!valid) { |
| | | return |
| | | } |
| | | this.attendLoading = true |
| | | var data = JSON.stringify({ |
| | | 'attendanceDate': this.attform.attendTime, |
| | | 'userId': this.attform.userId |
| | | }) |
| | | crudAttendance.addAttendanceInfo(data).then(res => { |
| | | this.attendVisible = false |
| | | this.attendLoading = false |
| | | this.crud.notify('考勤信息提交成功', CRUD.NOTIFICATION_TYPE.SUCCESS) |
| | | this.crud.toQuery() |
| | | if (this.$refs['attform']) { |
| | | this.$refs['attform'].resetFields() |
| | | } |
| | | }).catch(() => { |
| | | this.attendLoading = false |
| | | }) |
| | | }) |
| | | }, |
| | | // 关闭 |
| | | closeCard() { |
| | | if (this.$refs['makeUpCardForm']) { |
| | | this.$refs['makeUpCardForm'].resetFields() |
| | | } |
| | | if (this.$refs['goOutForm']) { |
| | | this.$refs['goOutForm'].resetFields() |
| | | } |
| | | if (this.$refs['bussForm']) { |
| | | this.$refs['bussForm'].resetFields() |
| | | } |
| | | if (this.$refs['attform']) { |
| | | this.$refs['attform'].resetFields() |
| | | } |
| | | this.crud.cancelCU() |
| | | this.makeUpCardVisible = false |
| | | this.goOutVisible = false |
| | | this.bussVisible = false |
| | | this.attendVisible = false |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .attCss { |
| | | font-size: 12px; |
| | | text-align: center; |
| | | } |
| | | </style> |
| | |
| | | </crudOperation> |
| | | </div> |
| | | <!--表单组件--> |
| | | <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="570px"> |
| | | <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="70px"> |
| | | <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="600px"> |
| | | <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px"> |
| | | <el-form-item label="用户名" prop="username"> |
| | | <el-input v-model="form.username" @keydown.native="keydown($event)" /> |
| | | </el-form-item> |
| | |
| | | <el-input v-model="form.email" /> |
| | | </el-form-item> |
| | | <el-form-item label="性别"> |
| | | <el-radio-group v-model="form.gender" style="width: 178px"> |
| | | <el-radio-group v-model="form.gender" style="width: 184px"> |
| | | <el-radio label="男">男</el-radio> |
| | | <el-radio label="女">女</el-radio> |
| | | </el-radio-group> |
| | |
| | | <el-date-picker |
| | | v-model="form.birthday" |
| | | type="date" |
| | | style="width: 178px" |
| | | style="width: 184px" |
| | | placeholder="请选择" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="住址" prop="address"> |
| | | <el-input v-model="form.address" style="width: 437px" /> |
| | | <el-input v-model="form.address" style="width: 461px" /> |
| | | </el-form-item> |
| | | <el-form-item label="部门" prop="dept.id"> |
| | | <treeselect |
| | | v-model="form.dept.id" |
| | | :options="depts" |
| | | :load-options="loadDepts" |
| | | style="width: 178px" |
| | | style="width: 184px" |
| | | placeholder="选择部门" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="岗位" prop="jobs"> |
| | | <el-select |
| | | v-model="jobDatas" |
| | | style="width: 178px" |
| | | style="width: 184px" |
| | | multiple |
| | | :multiple-limit="1" |
| | | placeholder="请选择" |
| | |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="排班" prop="sysRostering.id"> |
| | | <el-select v-model="form.sysRostering.id" clearable style="width: 178px" placeholder="请选择"> |
| | | <el-select v-model="form.sysRostering.id" clearable style="width: 184px" placeholder="请选择"> |
| | | <el-option |
| | | v-for="item in rosterings" |
| | | :key="item.id" |
| | | :label="item.name" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item v-if="crud.status.add == crudStatusPrepared" label="级别" prop="levelId"> |
| | | <el-select v-model="form.levelId" clearable style="width: 184px" placeholder="请选择"> |
| | | <el-option |
| | | v-for="item in levels" |
| | | :key="item.id" |
| | | :label="item.name" |
| | | :value="item.id" |
| | |
| | | <el-form-item label="钉钉号" prop="dingding"> |
| | | <el-input v-model="form.dingding" /> |
| | | </el-form-item> |
| | | <el-form-item v-if="crud.status.add == crudStatusPrepared" label="级别" prop="levelId"> |
| | | <el-select v-model="form.levelId" clearable style="width: 178px" placeholder="请选择"> |
| | | <el-option |
| | | v-for="item in levels" |
| | | :key="item.id" |
| | | :label="item.name" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | <el-form-item label="企微号" prop="weComId"> |
| | | <el-input v-model="form.weComId" /> |
| | | </el-form-item> |
| | | <el-form-item label="状态"> |
| | | <el-radio-group v-model="form.enabled" :disabled="form.id === user.id"> |
| | | <el-radio-group v-model="form.enabled" :disabled="form.id === user.id" style="width: 184px"> |
| | | <el-radio |
| | | v-for="item in dict.user_status" |
| | | :key="item.id" |
| | |
| | | >{{ item.label }}</el-radio> |
| | | </el-radio-group> |
| | | </el-form-item> |
| | | <el-form-item v-if="!isEditing" label="实习时间" prop="internshipTime" label-width="68px"> |
| | | <el-select v-model="form.internshipTime" clearable style="width: 437px"> |
| | | <el-form-item v-if="!isEditing" label="实习时间" prop="internshipTime"> |
| | | <el-select v-model="form.internshipTime" clearable style="width: 461px"> |
| | | <el-option v-for="item in internshipTimeList" :key="item.id" :label="item.label" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="公司" prop="company.id"> |
| | | <el-select v-model="form.company.id" clearable style="width: 437px"> |
| | | <el-select v-model="form.company.id" clearable style="width: 461px"> |
| | | <el-option v-for="item in companyList" :key="item.id" :label="item.label" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="角色" prop="roles"> |
| | | <el-select |
| | | v-model="roleDatas" |
| | | style="width: 437px" |
| | | style="width: 461px" |
| | | multiple |
| | | placeholder="请选择" |
| | | @remove-tag="deleteTag" |
| | |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="操作公司" prop="companys"> |
| | | <el-select v-model="companyDatas" clearable multiple collapse-tags style="width: 437px" @remove-tag="deleteCompanyTag" @change="changeCompany"> |
| | | <el-select v-model="companyDatas" clearable multiple collapse-tags style="width: 461px" @remove-tag="deleteCompanyTag" @change="changeCompany"> |
| | | <el-option v-for="item in companyList" :key="item.id" :label="item.label" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | |
| | | let userRoles = [] |
| | | let userJobs = [] |
| | | let userCompanys = [] |
| | | const defaultForm = { id: null, username: null, company: { id: null }, internshipTime: null, nickName: null, gender: '男', email: null, enabled: 'false', roles: [], jobs: [], dept: { id: null }, phone: null, birthday: null, address: null, dingding: null, sysRostering: { id: null }, levelId: null, companys: [] } |
| | | const defaultForm = { id: null, username: null, company: { id: null }, internshipTime: null, nickName: null, gender: '男', email: null, enabled: 'false', roles: [], jobs: [], dept: { id: null }, phone: null, birthday: null, address: null, dingding: null, weComId: null, sysRostering: { id: null }, levelId: null, companys: [] } |
| | | export default { |
| | | name: 'User', |
| | | components: { Treeselect, crudOperation, rrOperation, udOperation, pagination, DateRangePicker }, |
| | |
| | | dingding: [ |
| | | { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' } |
| | | ], |
| | | weComId: [ |
| | | { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' } |
| | | ], |
| | | address: [ |
| | | { min: 2, max: 100, message: '长度在 2 到 100 个字符', trigger: 'blur' } |
| | | ], |