ClockinView.java 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package thyyxxk.webserver.entity.clockin;
  2. import lombok.Data;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.joda.time.Interval;
  5. import org.joda.time.Period;
  6. import java.text.ParseException;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. @Data
  10. @Slf4j
  11. public class ClockinView {
  12. private String checkinDate; // 日期
  13. private String name; // 姓名
  14. private String userid; // 工号
  15. private String dept; // 科室
  16. private Integer times = 0; // 打卡次数
  17. private String worktime=""; // 工作时长(小时)
  18. private String checkinHourOn; // 上班打卡时间
  19. private String checkinAddrOn; // 上班打卡地点
  20. private String checkinStateOn; // 上班打卡状态
  21. private String notesOn; // 上班打卡备注
  22. private String checkinHourOff; // 下班打卡时间
  23. private String checkinAddrOff; // 下班打卡地点
  24. private String checkinStateOff; // 下班打卡状态
  25. private String notesOff; // 下班打卡备注
  26. public ClockinView(Clockin param) {
  27. this.checkinDate = param.getCheckinDate();
  28. this.name = param.getName();
  29. this.userid = param.getUserid();
  30. this.dept = param.getDept();
  31. }
  32. public void setInfo(Clockin param) {
  33. if (param.getCheckinType().equals("上班打卡")) {
  34. this.checkinHourOn = param.getCheckinHour();
  35. this.checkinAddrOn = param.getLocationTitle();
  36. this.checkinStateOn =
  37. param.getExceptionType().equals("") ?
  38. "正常" : param.getExceptionType();
  39. this.notesOn = param.getNotes();
  40. if (!getCheckinHourOn().equals("") && !getCheckinStateOn().equals("未打卡")) {
  41. times ++;
  42. }
  43. } else if (param.getCheckinType().equals("下班打卡")){
  44. this.checkinHourOff = param.getCheckinHour();
  45. this.checkinAddrOff = param.getLocationTitle();
  46. this.checkinStateOff =
  47. param.getExceptionType().equals("") ?
  48. "正常" : param.getExceptionType();
  49. this.notesOff = param.getNotes();
  50. if (!getCheckinHourOff().equals("") && !getCheckinStateOff().equals("未打卡")) {
  51. times ++;
  52. }
  53. }
  54. if (getWorktime().equals("")) {
  55. setWorktime(calculateWorktime());
  56. }
  57. }
  58. private String calculateWorktime() {
  59. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
  60. if (getCheckinHourOn() == null || getCheckinHourOff() == null
  61. || getCheckinHourOn().equals("") || getCheckinHourOff().equals(""))
  62. return "";
  63. try {
  64. Date date1 = simpleDateFormat.parse("2020-01-01 " + getCheckinHourOn());
  65. Date date2 = simpleDateFormat.parse("2020-01-01 " + getCheckinHourOff());
  66. if (date2.before(date1))
  67. return "";
  68. return diff(date1,date2);
  69. } catch (ParseException e) {
  70. log.error("计算工作时长出错", e);
  71. }
  72. return "";
  73. }
  74. private String diff(Date date1, Date date2) {
  75. Interval interval = new Interval(date1.getTime(), date2.getTime());
  76. Period period = interval.toPeriod();
  77. int hour = period.getHours();
  78. double min = period.getMinutes();
  79. double suffix = min / 60;
  80. return String.format("%.1f 小时", hour+suffix);
  81. }
  82. public String getCheckinStateOn() {
  83. return null == checkinStateOn ? "未打卡" : (checkinStateOn).trim();
  84. }
  85. public String getCheckinStateOff() {
  86. return null == checkinStateOff ? "未打卡" : (checkinStateOff).trim();
  87. }
  88. }