| | |
| | | /*
|
| | | * 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.
|
| | | */
|
| | | * 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 lombok.RequiredArgsConstructor;
|
| | | import me.zhengjie.exception.BadRequestException;
|
| | | import me.zhengjie.modules.approval.domain.ApproveEvent;
|
| | | import me.zhengjie.modules.approval.repository.ApproveEventRepository;
|
| | | import me.zhengjie.modules.approval.service.TemplateControlFieldService;
|
| | | import me.zhengjie.modules.approval.service.mapstruct.ApproveEventMapper;
|
| | | import me.zhengjie.modules.attendance.domain.*;
|
| | | import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository;
|
| | | import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository;
|
| | |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutQueryCriteria;
|
| | | import me.zhengjie.modules.attendance.service.mapstruct.AttendanceGoOutMapper;
|
| | | import me.zhengjie.modules.constant.Constant;
|
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService;
|
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
|
| | | import me.zhengjie.modules.system.domain.DictDetail;
|
| | | import me.zhengjie.modules.system.domain.Role;
|
| | | import me.zhengjie.modules.system.domain.SysRostering;
|
| | | import me.zhengjie.modules.system.domain.User;
|
| | |
| | | import java.time.temporal.ChronoUnit;
|
| | | import java.util.*;
|
| | | import java.util.function.Function;
|
| | | import java.util.stream.Collectors;
|
| | | import java.util.stream.Stream;
|
| | |
|
| | | /**
|
| | | * @website https://eladmin.vip
|
| | | * @description 服务实现
|
| | | * @author wcd
|
| | | * @date 2023-01-04
|
| | | **/
|
| | | * @author wcd
|
| | | * @website https://eladmin.vip
|
| | | * @description 服务实现
|
| | | * @date 2023-01-04
|
| | | **/
|
| | | @Service
|
| | | @RequiredArgsConstructor
|
| | | public class AttendanceGoOutServiceImpl implements AttendanceGoOutService {
|
| | |
| | | private final AttendanceService attendanceService;
|
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository;
|
| | | private final AttendanceLeaveServiceImpl attendanceLeaveService;
|
| | | private final OpaiDingTalkService opaiDingTalkService;
|
| | | private final AttendanceRepository attendanceRepository;
|
| | | private final AttendanceLeaveRepository attendanceLeaveRepository;
|
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
|
| | | private final ApproveEventRepository approveEventRepository;
|
| | | private final ApproveEventMapper approveEventMapper;
|
| | | private final DictDetailRepository dictDetailRepository;
|
| | | private final WeComServiceImpl weComService;
|
| | | private final TemplateControlFieldService templateControlFieldService;
|
| | |
|
| | | private final SysConfigHolidayService sysConfigHolidayService;
|
| | |
|
| | | @Override
|
| | | public Map<String,Object> queryAll(AttendanceGoOutQueryCriteria criteria, Pageable pageable){
|
| | | Page<AttendanceGoOut> page = attendanceGoOutRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
| | | public Map<String, Object> queryAll(AttendanceGoOutQueryCriteria criteria, Pageable pageable) {
|
| | | Page<AttendanceGoOut> page = attendanceGoOutRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
| | |
|
| | | //将实体转换为Dto(重写)
|
| | | Function<AttendanceGoOut, AttendanceGoOutDto> func = new Function<AttendanceGoOut, AttendanceGoOutDto>(){
|
| | | Function<AttendanceGoOut, AttendanceGoOutDto> func = new Function<AttendanceGoOut, AttendanceGoOutDto>() {
|
| | |
|
| | | @Override
|
| | | public AttendanceGoOutDto apply(AttendanceGoOut attendanceGoOut) {
|
| | |
| | | //查询审批用户名
|
| | | User appUser = userRepository.findById(attendanceGoOutDto.getApprovalUserId()).orElseGet(User::new);
|
| | | attendanceGoOutDto.setAppUserName(appUser.getNickName());
|
| | |
|
| | | // 查询企微最新审批变化记录
|
| | | if (ObjectUtils.isNotEmpty(attendanceGoOut.getWecomEventId())) {
|
| | | ApproveEvent event = approveEventRepository.findById(attendanceGoOut.getWecomEventId()).orElseGet(ApproveEvent::new);
|
| | | attendanceGoOutDto.setEvent(approveEventMapper.toDto(event));
|
| | | }
|
| | |
|
| | | return attendanceGoOutDto;
|
| | | }
|
| | | };
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public List<AttendanceGoOutDto> queryAll(AttendanceGoOutQueryCriteria criteria){
|
| | | public List<AttendanceGoOutDto> queryAll(AttendanceGoOutQueryCriteria criteria) {
|
| | | List<AttendanceGoOutDto> attendanceGoOutDtoList = attendanceGoOutMapper.toDto(attendanceGoOutRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
| | | attendanceGoOutDtoList.forEach(attendanceGoOutDto -> {
|
| | | //查询用户信息
|
| | |
| | | @Transactional
|
| | | public AttendanceGoOutDto findById(Long id) {
|
| | | AttendanceGoOut attendanceGoOut = attendanceGoOutRepository.findById(id).orElseGet(AttendanceGoOut::new);
|
| | | ValidationUtil.isNull(attendanceGoOut.getId(),"AttendanceGoOut","id",id);
|
| | | ValidationUtil.isNull(attendanceGoOut.getId(), "AttendanceGoOut", "id", id);
|
| | | return attendanceGoOutMapper.toDto(attendanceGoOut);
|
| | | }
|
| | |
|
| | |
| | | // Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
|
| | | // if ((sysConfigHolidayDto == null && !isWeekend) ||
|
| | | // sysConfigHolidayDto != null && Constant.DATE_TYPE_WEEKDAY.equals(sysConfigHolidayDto.getDateType())) {
|
| | | AttendanceGoOut attendanceGoOut = new AttendanceGoOut();
|
| | | //resUserId为null说明是添加,反之
|
| | | if (resources.getUserId() == null) {
|
| | | resources.setUserId(user.getId());
|
| | | }
|
| | | resources.setOutStartTime(Timestamp.valueOf(localDate.atTime(startTime)));
|
| | | resources.setOutEndTime(Timestamp.valueOf(localDate.atTime(endTime)));
|
| | | AttendanceGoOut attendanceGoOut = new AttendanceGoOut();
|
| | | //resUserId为null说明是添加,反之
|
| | | if (resources.getUserId() == null) {
|
| | | resources.setUserId(user.getId());
|
| | | }
|
| | | resources.setOutStartTime(Timestamp.valueOf(localDate.atTime(startTime)));
|
| | | resources.setOutEndTime(Timestamp.valueOf(localDate.atTime(endTime)));
|
| | |
|
| | | Double result = getRemainingTime(resources);
|
| | | resources.setOutDuration(result);
|
| | | resources.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_REVIEWED);
|
| | | attendanceGoOut.copy(resources);
|
| | | attendanceGoOutRepository.save(attendanceGoOut);
|
| | | Double result = getRemainingTime(resources);
|
| | | resources.setOutDuration(result);
|
| | | resources.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_REVIEWED);
|
| | |
|
| | | // 判断是否提交企微审批
|
| | | List<DictDetail> siteTypes = dictDetailRepository.findByDictName(Constant.APPROVAL_SITE_TYPE).stream().filter(siteType -> siteType.getValue().toLowerCase().equals("wecom")).collect(Collectors.toList());
|
| | | if (siteTypes.size() > 0) {
|
| | | // 添加企微申请参数
|
| | | resources.setWecomType(dictDetailRepository.findByDictNameAndValue("go_out_type", resources.getOutOfOfficeType()).getLabel());
|
| | | resources.setWecomLocation("暂无");
|
| | | resources.setWecomDateType(ElAdminConstant.Constant.TEMPLATE_DATE_TYPE_HOUR);
|
| | | resources.setWecomDuration(String.valueOf(new BigDecimal(resources.getOutDuration()).multiply(new BigDecimal(3600)).longValue()));
|
| | | resources.setWecomAttendanceType("4");
|
| | | // 提交申请
|
| | | String weComId = userRepository.findById(resources.getUserId()).orElse(new User()).getWeComId();
|
| | | Map<String, String> approvalResultMap = templateControlFieldService.createWecomApproval(resources, weComId);
|
| | | if (approvalResultMap.containsKey("spNo")) {
|
| | | resources.setWecomSpNo(approvalResultMap.get("spNo"));
|
| | | } else {
|
| | | throw new BadRequestException(approvalResultMap.containsKey("error") ? approvalResultMap.get("error") : "企微申请提交失败");
|
| | | }
|
| | | }
|
| | |
|
| | | attendanceGoOut.copy(resources);
|
| | | attendanceGoOutRepository.save(attendanceGoOut);
|
| | | // }
|
| | | // SysConfigHolidayDto sysConfigHolidayDto = sysConfigHolidayService.queryByHolidayDate(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
| | | // Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY;
|
| | |
| | | // attendanceGoOutRepository.save(attendanceGoOut);
|
| | | // }
|
| | | // }
|
| | | //发送钉钉给审批人
|
| | | List<String> sendList = new ArrayList<>();
|
| | | //查询审批者信息
|
| | | User appUser = userRepository.getOne(resources.getApprovalUserId());
|
| | | sendList.add(appUser.getDingding());
|
| | | opaiDingTalkService.sendNotice(sendList, "审批提醒", "### 审批提示 \n >" + user.getNickName() + " 提交了外出审批,请登录PMS系统处理", "card");
|
| | | }
|
| | | return attendanceGoOutMapper.toDto(resources);
|
| | | }
|
| | |
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void update(AttendanceGoOut resources) {
|
| | | AttendanceGoOut attendanceGoOut = attendanceGoOutRepository.findById(resources.getId()).orElseGet(AttendanceGoOut::new);
|
| | | ValidationUtil.isNull( attendanceGoOut.getId(),"AttendanceGoOut","id",resources.getId());
|
| | | ValidationUtil.isNull(attendanceGoOut.getId(), "AttendanceGoOut", "id", resources.getId());
|
| | | attendanceGoOut.copy(resources);
|
| | |
|
| | | //审核通过或者退回不能修改
|
| | | if(attendanceGoOut.getApprovalStatus().equals(Constant.GOOUT_APPROVE_STATUS_AGREE) || attendanceGoOut.getApprovalStatus().equals(Constant.GOOUT_APPROVE_STATUS_REFUSE)){
|
| | | if (attendanceGoOut.getApprovalStatus().equals(Constant.GOOUT_APPROVE_STATUS_AGREE) || attendanceGoOut.getApprovalStatus().equals(Constant.GOOUT_APPROVE_STATUS_REFUSE)) {
|
| | | throw new BadRequestException("审核通过或退回的不能进行修改");
|
| | | }
|
| | |
|
| | |
| | | User user1 = userRepository.getOne(SecurityUtils.getCurrentUserId());
|
| | | Role role = user1.getRoles().iterator().next();
|
| | | //除超管、总经理只能修改自己信息
|
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){
|
| | | if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())){
|
| | | if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) {
|
| | | if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())) {
|
| | | throw new BadRequestException("只能修改自己的记录");
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | /**
|
| | | * 验证其他状态的表是否有重复
|
| | | *
|
| | | * @param goStartTime
|
| | | * @param goEndTime
|
| | | */
|
| | | public void repeatValidation(String goStartTime, String goEndTime, Long userId){
|
| | | public void repeatValidation(String goStartTime, String goEndTime, Long userId) {
|
| | | // 查询请假表(时单位)
|
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.checkCreateLeaveTime(goStartTime,goEndTime, userId);
|
| | | if(attendanceLeaveList.size() > 0){
|
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.checkCreateLeaveTime(goStartTime, goEndTime, userId);
|
| | | if (attendanceLeaveList.size() > 0) {
|
| | | AttendanceLeave errorSysAskForLeave = attendanceLeaveList.get(0);
|
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日");
|
| | | throw new BadRequestException("请假时间冲突," + errorFormat.format(errorSysAskForLeave.getLeaveStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getLeaveEndTime())
|
| | | + "已经存在请假记录,请调整时间");
|
| | | }
|
| | | // 查询出差表
|
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(goStartTime.substring(0,10),goEndTime.substring(0,10), userId);
|
| | | if(attendanceBusinessTravelList.size() > 0){
|
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(goStartTime.substring(0, 10), goEndTime.substring(0, 10), userId);
|
| | | if (attendanceBusinessTravelList.size() > 0) {
|
| | | AttendanceBusinessTravel errorSysAskForLeave = attendanceBusinessTravelList.get(0);
|
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日");
|
| | | throw new BadRequestException("出差时间冲突," + errorFormat.format(errorSysAskForLeave.getTravelStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getTravelEndTime())
|
| | |
| | | //根据id查询记录
|
| | | Optional<AttendanceGoOut> attendanceGoOut = attendanceGoOutRepository.findById(id);
|
| | | //审核通过或者退回不能删除
|
| | | if(attendanceGoOut.get().getApprovalStatus().equals(Constant.GOOUT_APPROVE_STATUS_AGREE) || attendanceGoOut.get().getApprovalStatus().equals(Constant.GOOUT_APPROVE_STATUS_REFUSE)){
|
| | | if (attendanceGoOut.get().getApprovalStatus().equals(Constant.GOOUT_APPROVE_STATUS_AGREE) || attendanceGoOut.get().getApprovalStatus().equals(Constant.GOOUT_APPROVE_STATUS_REFUSE)) {
|
| | | throw new BadRequestException("审核通过或退回的不能进行删除");
|
| | | }
|
| | |
|
| | |
| | | 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(attendanceGoOut.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){
|
| | | if (role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL) {
|
| | | if (!Long.valueOf(attendanceGoOut.get().getUserId()).equals(SecurityUtils.getCurrentUserId())) {
|
| | | throw new BadRequestException("只能删除自己的记录");
|
| | | }
|
| | | }
|
| | |
| | | for (AttendanceGoOutDto attendanceGoOut : all) {
|
| | | String outOfOfficeType = attendanceGoOut.getOutOfOfficeType() != null ? dictDetailRepository.findByDictNameAndValue("go_out_type", attendanceGoOut.getOutOfOfficeType()).getLabel() : "";
|
| | | String outDurationUnit = attendanceGoOut.getDurationUnit() != null ? dictDetailRepository.findByDictNameAndValue(Constant.LEAVE_TIME_TYPE, attendanceGoOut.getDurationUnit()).getLabel() : "";
|
| | | Map<String,Object> map = new LinkedHashMap<>();
|
| | | Map<String, Object> map = new LinkedHashMap<>();
|
| | | map.put("申请者", attendanceGoOut.getUserName());
|
| | | map.put("审批者", attendanceGoOut.getAppUserName());
|
| | | map.put("外出开始时间", attendanceGoOut.getOutStartTime());
|
| | |
| | |
|
| | | /**
|
| | | * 计算外出时长
|
| | | *
|
| | | * @param attendanceGoOut
|
| | | * @return
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * 审核/撤销功能
|
| | | *
|
| | | * @param resources /
|
| | | */
|
| | | @Override
|
| | | public void updateApprove(AttendanceGoOut resources) throws Exception {
|
| | | AttendanceGoOut attendanceGoOut = attendanceGoOutRepository.findById(resources.getId()).orElseGet(AttendanceGoOut::new);
|
| | | ValidationUtil.isNull( attendanceGoOut.getId(),"AttendanceGoOut","id",resources.getId());
|
| | | ValidationUtil.isNull(attendanceGoOut.getId(), "AttendanceGoOut", "id", resources.getId());
|
| | | attendanceGoOut.copy(resources);
|
| | | attendanceGoOutRepository.save(attendanceGoOut);
|
| | | // 调用定时任务修改考勤记录
|
| | | List<User> userList = new ArrayList<>();
|
| | | if(ObjectUtils.isNotEmpty(attendanceGoOut.getUserId())){
|
| | | if (ObjectUtils.isNotEmpty(attendanceGoOut.getUserId())) {
|
| | | User user = userRepository.findById(attendanceGoOut.getUserId()).orElseGet(User::new);
|
| | | userList.add(user);
|
| | | }
|
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
| | | String attendanceDate = df.format(attendanceGoOut.getOutStartTime());
|
| | | weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate,userList);
|
| | | weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate, userList);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 批量审核(外出)
|
| | | *
|
| | | * @param request
|
| | | * @throws Exception
|
| | | */
|
| | |
| | | public void updateAgree(AgreeUpdateRequest request) throws Exception {
|
| | | for (Long id : request.getIds()) {
|
| | | AttendanceGoOut attendanceGoOut = attendanceGoOutRepository.findById(id).orElseGet(AttendanceGoOut::new);
|
| | | ValidationUtil.isNull( attendanceGoOut.getId(),"AttendanceGoOut","id",id);
|
| | | if (request.getNum().equals(Long.valueOf(1))){
|
| | | ValidationUtil.isNull(attendanceGoOut.getId(), "AttendanceGoOut", "id", id);
|
| | | if (request.getNum().equals(Long.valueOf(1))) {
|
| | | attendanceGoOut.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_AGREE);
|
| | | } else {
|
| | | attendanceGoOut.setApprovalStatus(Constant.GOOUT_APPROVE_STATUS_REFUSE);
|
| | |
| | | attendanceGoOutRepository.save(attendanceGoOut);
|
| | | // 调用定时任务修改考勤记录
|
| | | List<User> userList = new ArrayList<>();
|
| | | if(ObjectUtils.isNotEmpty(attendanceGoOut.getUserId())){
|
| | | if (ObjectUtils.isNotEmpty(attendanceGoOut.getUserId())) {
|
| | | User user = userRepository.findById(attendanceGoOut.getUserId()).orElseGet(User::new);
|
| | | userList.add(user);
|
| | | }
|
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
| | | String attendanceDate = df.format(attendanceGoOut.getOutStartTime());
|
| | | weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate,userList);
|
| | | weComService.getWeComAttendanceListOfNoonOrNight(attendanceDate, userList);
|
| | | }
|
| | | }
|
| | | } |