在 com.project.emos.wx.service 包中,创建 CheckinService 接口

    1. public interface CheckinService {
    2. /**
    3. * 检测当天是否可以签到
    4. * @param userId
    5. * @param date
    6. * @return
    7. */
    8. public String validCanCheckIn(int userId, String date);
    9. }

    在 com.project.emos.wx.service.impl 包中,创建 CheckinServiceImpl 实现类。

    1. /**
    2. * @author JianqingWeng
    3. * @Description
    4. * @create 2021-06-19 16:35
    5. */
    6. @Service
    7. @Scope("prototype")
    8. @Slf4j
    9. public class CheckinServiceImpl implements CheckinService {
    10. @Autowired
    11. private SystemConstants systemConstants;
    12. @Autowired
    13. private TbHolidaysDao holidaysDao;
    14. @Autowired
    15. private TbWorkdayDao workdayDao;
    16. @Autowired
    17. private TbCheckinDao checkinDao;
    18. @Override
    19. public String validCanCheckIn(int userId, String date) {
    20. boolean bool_1 = holidaysDao.searchTodayIsHolidays() != null ? true : false;
    21. boolean bool_2 = workdayDao.searchTodayIsWorkday() != null ? true : false;
    22. String type = "工作日";
    23. if (DateUtil.date().isWeekend()) {
    24. type = "节假日";
    25. }
    26. if (bool_1) {
    27. type = "节假日";
    28. } else if (bool_2) {
    29. type = "工作日";
    30. }
    31. if (type.equals("节假日")) {
    32. return "节假日不需要考勤";
    33. }
    34. DateTime now = DateUtil.date();
    35. String start = DateUtil.today() + " "
    36. + systemConstants.attendanceStartTime;
    37. String end = DateUtil.today() + " "
    38. + systemConstants.attendanceEndTime;
    39. DateTime attendanceStart = DateUtil.parse(start);
    40. DateTime attendanceEnd = DateUtil.parse(end);
    41. if (now.isBefore(attendanceStart)) {
    42. return "没有到上班考勤开始时间";
    43. }
    44. if (now.isAfter(attendanceEnd)) {
    45. return "超过了上班考勤结束时间";
    46. }
    47. // 执行到这里才真正的要打卡
    48. HashMap map = new HashMap();
    49. map.put("userId", userId);
    50. map.put("date", date);
    51. map.put("start", start);
    52. map.put("end", end);
    53. boolean bool = checkinDao.haveCheckin(map) != null ? true : false;
    54. return bool ? "今日已经考勤,不用重复考勤" : "可以考勤";
    55. }
    56. }