| | |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceDto; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService; |
| | | import me.zhengjie.modules.system.domain.Job; |
| | | import me.zhengjie.modules.system.domain.Role; |
| | | import me.zhengjie.modules.system.domain.SysConfigProportion; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.RoleRepository; |
| | | import me.zhengjie.modules.system.repository.SysConfigProportionRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.function.Function; |
| | | |
| | | /** |
| | |
| | | private final OpaiDingTalkService opaiDingTalkService; |
| | | private final RoleRepository roleRepository; |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final SysConfigProportionRepository sysConfigProportionRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(AttendanceCardreplacementQueryCriteria criteria, Pageable pageable){ |
| | | //查询当前登录人 |
| | | User user = userRepository.findById(SecurityUtils.getCurrentUserId()).get(); |
| | | //当前登录人角色包含职员就添加查询条件只能查询自己申请的或审批人是自己的记录 |
| | | if (user.getRoles().contains(roleRepository.findById(Constant.JOB_STAFF).get())) { |
| | | criteria.setApprover(SecurityUtils.getCurrentUserId()); |
| | | } |
| | | Page<AttendanceCardreplacement> page = attendanceCardreplacementRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | //将实体转换为Dto(重写) |
| | | Function<AttendanceCardreplacement, AttendanceCardreplacementDto> func = new Function<AttendanceCardreplacement,AttendanceCardreplacementDto >(){ |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AttendanceCardreplacementDto create(AttendanceCardreplacement resources) throws Exception { |
| | | |
| | | //查询补卡次数(每个月5次) |
| | | getCardreplacement(resources.getCardReplacementTime(), resources.getUserId()); |
| | | |
| | | //查询补卡记录是否存在 |
| | | AttendanceCardreplacement attendanceCardreplacement = attendanceCardreplacementRepository.findByUserIdAndCardReplacementTime(resources.getUserId(),resources.getCardReplacementTime()); |
| | | if(ObjectUtils.isNotEmpty(attendanceCardreplacement)) { |
| | |
| | | } |
| | | |
| | | resources.setApprovalStatus(Constant.CARD_APPROVE_STATUS_REVIEWED); |
| | | //查询补卡次数(待加入)? |
| | | |
| | | //发送给审批者 |
| | | List<String> sendList = new ArrayList<>(); |
| | |
| | | throw new BadRequestException("考勤记录不存在"); |
| | | } |
| | | |
| | | //查询补卡次数(每个月5次) |
| | | getCardreplacement(resources.getCardReplacementTime(), resources.getUserId()); |
| | | |
| | | //获取当前登入人信息 |
| | | 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("只能修改自己的记录"); |
| | | } |
| | | } |
| | | //审核通过或者退回不能删除 |
| | | if(attendanceCardreplacement.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_AGREE) || attendanceCardreplacement.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_REFUSE)){ |
| | | throw new BadRequestException("审核通过或退回的不能进行修改"); |
| | | } |
| | | |
| | | attendanceCardreplacementRepository.save(attendanceCardreplacement); |
| | | } |
| | | |
| | | /** |
| | | * 查询剩余补卡次数 |
| | | */ |
| | | public void getCardreplacement(Timestamp cardReplacementTime, Long userId){ |
| | | // 日期时间格式化 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 补卡时间字符串 |
| | | String cardReplacementTimeStr = sdf.format(cardReplacementTime); |
| | | // 查询当月的补卡记录的条数 |
| | | Integer count = attendanceCardreplacementRepository.count(userId, cardReplacementTimeStr.substring(0,7)); |
| | | // 查询配置表的每月补卡次数 |
| | | SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("每月可补卡次数"); |
| | | if(count >= sysConfigProportion.getProportion()){ |
| | | throw new BadRequestException("补卡次数用尽,请联系管理员"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | attendance.setActualWorkStartTime(resources.getCardReplacementTime()); |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NORMAL); |
| | | // 减少补卡次数待加入? |
| | | }else if (resources.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_REFUSE)){ |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED); |
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED); |
| | |
| | | if (resources.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_AGREE)) { |
| | | // set考勤打卡时间和打卡状态 |
| | | attendance.setActualWorkEndTime(resources.getCardReplacementTime()); |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED); |
| | | // 减少补卡次数待加入? |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NORMAL); |
| | | }else if (resources.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_REFUSE)){ |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED); |
| | |
| | | @Override |
| | | public void deleteAll(Long[] ids) { |
| | | for (Long id : ids) { |
| | | //获取当前登入人信息 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Role role = user.getRoles().iterator().next(); |
| | | //根据id查询记录 |
| | | Optional<AttendanceCardreplacement> attendanceCardreplacement = attendanceCardreplacementRepository.findById(id); |
| | | //除超管、总经理只能删除自己信息 |
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){ |
| | | if (!Long.valueOf(attendanceCardreplacement.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){ |
| | | throw new BadRequestException("只能删除自己的记录"); |
| | | } |
| | | } |
| | | //审核通过或者退回不能删除 |
| | | if(attendanceCardreplacement.get().getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_AGREE) || attendanceCardreplacement.get().getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_REFUSE)){ |
| | | throw new BadRequestException("审核通过或退回的不能进行删除"); |
| | | } |
| | | attendanceCardreplacementRepository.deleteById(id); |
| | | } |
| | | } |
| | |
| | | public void download(List<AttendanceCardreplacementDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (AttendanceCardreplacementDto attendanceCardreplacement : all) { |
| | | String attCardreplacementType = attendanceCardreplacement.getApprovalStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.CARD_APPROVE_STATUS, attendanceCardreplacement.getApprovalStatus()).getLabel() : ""; |
| | | String attCardReplacementDistinguish = attendanceCardreplacement.getCardReplacementDistinguish() != null ? dictDetailRepository.findByDictNameAndValue(Constant.CARD_REPLACEMENT_DIFFERENTIATION, attendanceCardreplacement.getCardReplacementDistinguish()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("用户id", attendanceCardreplacement.getUserId()); |
| | | map.put("审批用户id", attendanceCardreplacement.getApprovalUserId()); |
| | | map.put("补卡时间", attendanceCardreplacement.getCardReplacementTime()); |
| | | map.put("补卡原因", attendanceCardreplacement.getCardReplacementReason()); |
| | | map.put("审批状态", attendanceCardreplacement.getApprovalStatus()); |
| | | map.put("审批状态", attCardreplacementType); |
| | | map.put("审批说明", attendanceCardreplacement.getApprovalDescription()); |
| | | map.put("补卡区分", attendanceCardreplacement.getCardReplacementDistinguish()); |
| | | map.put("补卡区分", attCardReplacementDistinguish); |
| | | map.put("备注", attendanceCardreplacement.getRemarks()); |
| | | map.put("创建者", attendanceCardreplacement.getCreateBy()); |
| | | map.put("创建时间", attendanceCardreplacement.getCreateTime()); |