Browse Source

考勤修改,增加调休设置。

zhengqiang 5 years ago
parent
commit
5662521afd

+ 34 - 27
common/src/main/java/com/jpsoft/smart/modules/base/entity/HolidayInfo.java

@@ -4,6 +4,7 @@ import java.io.Serializable;
 import java.util.Date;
 import java.text.SimpleDateFormat;
 import java.math.BigDecimal;
+
 import org.springframework.format.annotation.DateTimeFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
@@ -11,62 +12,68 @@ import io.swagger.annotations.ApiModel;
 import lombok.Data;
 
 /**
-  描述:base_holiday_info的实体类
+ * 描述:base_holiday_info的实体类
  */
 @Data
 @ApiModel(value = "base_holiday_info的实体类")
 public class HolidayInfo {
 	/**
-	 *主键
+	 * 主键
 	 */
-        @ApiModelProperty(value = "主键")
+	@ApiModelProperty(value = "主键")
 	private String id;
 	/**
-	 *节假日名称
+	 * 节假日名称
 	 */
-        @ApiModelProperty(value = "节假日名称")
+	@ApiModelProperty(value = "节假日名称")
 	private String holidayName;
 	/**
-	 *节假日开始日期
+	 * 节假日开始日期
 	 */
-    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
-	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
-	    @ApiModelProperty(value = "节假日开始日期")
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
+	@ApiModelProperty(value = "节假日开始日期")
 	private Date beginDate;
 	/**
-	 *节假日结束日期
+	 * 节假日结束日期
 	 */
-    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
-	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
-	    @ApiModelProperty(value = "节假日结束日期")
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
+	@ApiModelProperty(value = "节假日结束日期")
 	private Date endDate;
 	/**
-	 *创建人
+	 * 创建人
 	 */
-        @ApiModelProperty(value = "创建人")
+	@ApiModelProperty(value = "创建人")
 	private String createBy;
 	/**
-	 *创建时间
+	 * 创建时间
 	 */
-    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
-	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
-	    @ApiModelProperty(value = "创建时间")
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
+	@ApiModelProperty(value = "创建时间")
 	private Date createTime;
 	/**
-	 *更新人
+	 * 更新人
 	 */
-        @ApiModelProperty(value = "更新人")
+	@ApiModelProperty(value = "更新人")
 	private String updateBy;
 	/**
-	 *更新时间
+	 * 更新时间
 	 */
-    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
-	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
-	    @ApiModelProperty(value = "更新时间")
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
+	@ApiModelProperty(value = "更新时间")
 	private Date updateTime;
 	/**
-	 *是否删除
+	 * 是否删除
 	 */
-        @ApiModelProperty(value = "是否删除")
+	@ApiModelProperty(value = "是否删除")
 	private Boolean delFlag;
+
+	@ApiModelProperty(value = "是否需要上班")
+	private Boolean working;
+
+	@ApiModelProperty(value = "参考上班日")
+	private int refWeekday;
 }

+ 3 - 1
common/src/main/java/com/jpsoft/smart/modules/base/service/HolidayInfoService.java

@@ -17,5 +17,7 @@ public interface HolidayInfoService {
 	int delete(String id);
 	List<HolidayInfo> list();
 	Page<HolidayInfo> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
-    Set<String> getHolidaySetByDate(Date startDate, Date endDate);
+	Set<String> getHolidaySetByDate(Date startDate,Date endDate,Boolean working);
+	Map<String,HolidayInfo> getHolidayMapByDate(Date startDate,Date endDate,Boolean working);
+
 }

+ 31 - 6
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/HolidayInfoServiceImpl.java

@@ -69,23 +69,48 @@ public class HolidayInfoServiceImpl implements HolidayInfoService {
         return page;
 	}
 
+
 	@Override
-	public Set<String> getHolidaySetByDate(Date startDate,Date endDate) {
+	public Set<String> getHolidaySetByDate(Date startDate,Date endDate,Boolean working) {
 		List<HolidayInfo> list = holidayInfoDAO.findByDate(startDate,endDate);
 
 		Set<String> holidaySet = new TreeSet<>();
 
 		for (HolidayInfo holidayInfo : list) {
-			DateTime beginTime = new DateTime(holidayInfo.getBeginDate());
-			DateTime endTime = new DateTime(holidayInfo.getEndDate());
+			if(holidayInfo.getWorking()==working){
+				DateTime beginTime = new DateTime(holidayInfo.getBeginDate());
+				DateTime endTime = new DateTime(holidayInfo.getEndDate());
 
-			int days = Days.daysBetween(beginTime,endTime).getDays();
+				int days = Days.daysBetween(beginTime,endTime).getDays();
 
-			for (int i = 0; i <= days; i++) {
-				holidaySet.add(beginTime.plusDays(i).toString("yyyy-MM-dd"));
+				for (int i = 0; i <= days; i++) {
+					holidaySet.add(beginTime.plusDays(i).toString("yyyy-MM-dd"));
+				}
 			}
 		}
 
 		return holidaySet;
 	}
+
+	@Override
+	public Map<String,HolidayInfo> getHolidayMapByDate(Date startDate,Date endDate,Boolean working) {
+		List<HolidayInfo> list = holidayInfoDAO.findByDate(startDate,endDate);
+
+		Map<String,HolidayInfo> holidayMap = new HashMap<>();
+
+		for (HolidayInfo holidayInfo : list) {
+			if(holidayInfo.getWorking()==working){
+				DateTime beginTime = new DateTime(holidayInfo.getBeginDate());
+				DateTime endTime = new DateTime(holidayInfo.getEndDate());
+
+				int days = Days.daysBetween(beginTime,endTime).getDays();
+
+				for (int i = 0; i <= days; i++) {
+					holidayMap.put(beginTime.plusDays(i).toString("yyyy-MM-dd"),holidayInfo);
+				}
+			}
+		}
+
+		return holidayMap;
+	}
 }

+ 26 - 6
common/src/main/java/com/jpsoft/smart/modules/business/service/impl/WorkAttendanceServiceImpl.java

@@ -10,6 +10,7 @@ import com.jpsoft.smart.modules.base.dao.CompanyInfoDAO;
 import com.jpsoft.smart.modules.base.dao.PersonInfoDAO;
 import com.jpsoft.smart.modules.base.entity.AlarmConfig;
 import com.jpsoft.smart.modules.base.entity.CompanyInfo;
+import com.jpsoft.smart.modules.base.entity.HolidayInfo;
 import com.jpsoft.smart.modules.base.entity.PersonInfo;
 import com.jpsoft.smart.modules.base.service.HolidayInfoService;
 import com.jpsoft.smart.modules.common.utils.StringUtils;
@@ -114,13 +115,22 @@ public class WorkAttendanceServiceImpl implements WorkAttendanceService {
 			String date = recordTime.toString("yyyy-MM-dd");
 
 			//是否节假日
-			Set<String> holidaySet = holidayInfoService.getHolidaySetByDate(recordDate,recordDate);
+			Set<String> holidaySet = holidayInfoService.getHolidaySetByDate(recordDate,recordDate,false);
 
-			if (holidaySet.contains(recordDate)){
+			//虽然放假但正常上班
+			Map<String, HolidayInfo> fakeHolidayMap = holidayInfoService.getHolidayMapByDate(recordDate, recordDate,true);
+
+			if (holidaySet.contains(date)){
 				return false;
 			}
 
 			PersonInfo personInfo = personInfoDAO.get(personId);
+
+			if (personInfo==null){
+				log.error("设备上保存的人员编号与服务器不一致,personId=" + personId);
+				return false;
+			}
+
 			CompanyInfo companyInfo = companyInfoDAO.get(personInfo.getCompanyId());
 
 			String[] arr = companyInfo.getCode().split(",");
@@ -137,8 +147,18 @@ public class WorkAttendanceServiceImpl implements WorkAttendanceService {
 
 			if (configList != null) {
 				for (AlarmConfig alarmConfig : configList) {
+					int weekday = recordTime.getDayOfWeek();
+
+					if(fakeHolidayMap.containsKey(date)){
+						//虽然放假但需要工作
+						HolidayInfo holidayInfo = fakeHolidayMap.get(date);
+
+						//参考工作日
+						weekday = holidayInfo.getRefWeekday();
+					}
+
 					//是否工作日
-					if (alarmConfig.getWeekdays().indexOf(String.valueOf(recordTime.getDayOfWeek())) == -1) {
+					if (alarmConfig.getWeekdays().indexOf(String.valueOf(weekday)) == -1) {
 						continue;
 					}
 
@@ -151,11 +171,11 @@ public class WorkAttendanceServiceImpl implements WorkAttendanceService {
 					if (alarmConfig.getClassifier().equals(1)) {
 						//todo 上班考勤
 
-						//准时上班
-						if (recordTime.compareTo(startTime)>0 && recordTime.compareTo(attendanceTime)<=0){
+						//上班加1分钟
+						if (recordTime.compareTo(startTime)>0 && recordTime.compareTo(attendanceTime.plusMinutes(1))<=0){
 							attendanceResult = WorkAttendance.SUCCESS;
 						}
-						else if(recordTime.compareTo(attendanceTime)>0 && recordTime.compareTo(endTime)<=0){
+						else if(recordTime.compareTo(attendanceTime.plusMinutes(1))>0 && recordTime.compareTo(endTime)<=0){
 							attendanceResult = WorkAttendance.LATE;
 						}
 

+ 15 - 2
common/src/main/resources/mapper/base/HolidayInfo.xml

@@ -13,6 +13,8 @@
         <result property="updateBy" column="update_by"/>
         <result property="updateTime" column="update_time"/>
         <result property="delFlag" column="del_flag"/>
+        <result property="working" column="working_"/>
+        <result property="refWeekday" column="ref_weekday"/>
     </resultMap>
     <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.HolidayInfo">
         <!--
@@ -22,7 +24,8 @@
         -->
         <![CDATA[
 		insert into base_holiday_info
-	    (id_,holiday_name,begin_date,end_date,create_by,create_time,update_by,update_time,del_flag)
+	    (id_,holiday_name,begin_date,end_date,create_by,create_time,update_by,update_time,
+	    del_flag,working_,ref_weekday)
 		values
 		(
             #{id,jdbcType=VARCHAR}
@@ -34,6 +37,8 @@
             ,#{updateBy,jdbcType=VARCHAR}
             ,#{updateTime,jdbcType= TIMESTAMP }
             ,#{delFlag,jdbcType= NUMERIC }
+            ,#{working,jdbcType= NUMERIC }
+            ,#{refWeekday,jdbcType= NUMERIC }
 		)
 	]]>
     </insert>
@@ -67,12 +72,20 @@
             <if test="delFlag!=null">
                 del_flag=#{delFlag,jdbcType= NUMERIC },
             </if>
+            <if test="working!=null">
+                working_=#{working,jdbcType= NUMERIC },
+            </if>
+            <if test="refWeekday!=null">
+                ref_weekday=#{refWeekday,jdbcType= NUMERIC },
+            </if>
         </set>
         where id_=#{id}
     </update>
     <select id="get" parameterType="string" resultMap="HolidayInfoMap">
         select
-        id_,holiday_name,begin_date,end_date,create_by,create_time,update_by,update_time,del_flag from base_holiday_info
+        id_,holiday_name,begin_date,end_date,create_by,create_time,update_by,
+        update_time,del_flag,working_,ref_weekday
+        from base_holiday_info
         where id_=#{0}
     </select>
     <select id="exist" parameterType="string" resultType="int">

+ 1 - 1
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/IndividualLogApiController.java

@@ -202,7 +202,7 @@ public class IndividualLogApiController {
             int totalDays = 0;       //连续测温天数
 
             //最近一年的节假日
-            Set<String> holidaySet = holidayInfoService.getHolidaySetByDate(today.minusDays(364).toDate(),today.plusDays(1).toDate());
+            Set<String> holidaySet = holidayInfoService.getHolidaySetByDate(today.minusDays(364).toDate(),today.plusDays(1).toDate(),false);
 
             //查询当前用户的考勤设置
             Set<Integer> weekdaySet = alarmConfigService.getWeekdaySetByCompanyId(person.getCompanyId());

+ 39 - 11
web/src/main/java/com/jpsoft/smart/schduled/UnmeasureTemperatureAlarmTask.java

@@ -108,21 +108,35 @@ public class UnmeasureTemperatureAlarmTask {
 
         int affectCount = 0;
 
-        //更新时间段内节假日
-        Set<String> holidaySet = holidayInfoService.getHolidaySetByDate(startDate,endDate);
+        //放假日期
+        Set<String> realHolidaySet = holidayInfoService.getHolidaySetByDate(startDate,endDate,false);
+
+        //虽然放假但正常上班
+        Map<String,HolidayInfo> fakeHolidayMap = holidayInfoService.getHolidayMapByDate(startDate,endDate,true);
 
         for (int i=0;i<days;i++){
             DateTime now = dt1.plusDays(i);
 
             String date = now.toString("yyyy-MM-dd");
 
-            if (holidaySet.contains(date)){
+            //排除真放假日
+            if (realHolidaySet.contains(date)){
                 continue;
             }
 
             for (AlarmConfig alarmConfig : configList) {
-                //是否工作日
-                if (alarmConfig.getWeekdays().indexOf(String.valueOf(now.getDayOfWeek())) == -1) {
+                int weekday = now.getDayOfWeek();
+
+                if(fakeHolidayMap.containsKey(date)){
+                    //虽然放假但需要工作
+                    HolidayInfo holidayInfo = fakeHolidayMap.get(date);
+
+                    //当前参考工作日
+                    weekday = holidayInfo.getRefWeekday();
+                }
+
+                if (alarmConfig.getWeekdays().indexOf(String.valueOf(weekday)) == -1) {
+                    //当前日期不属于本轮考勤设置的工作日
                     continue;
                 }
 
@@ -136,7 +150,7 @@ public class UnmeasureTemperatureAlarmTask {
                     companyCode += "%";
                 }
 
-                //todo 查询该单位当前时间段考勤人员列表
+                //todo 查询当前时间段学生测温情况
                 List<PersonInfo> attendanceList = personDeviceLogService.queryAttendanceList(companyCode,startTime.toDate(),endTime.toDate());
 
                 for (PersonInfo personInfo: attendanceList) {
@@ -156,10 +170,11 @@ public class UnmeasureTemperatureAlarmTask {
                             //上班算最早一次考勤
                             personDeviceLog = logList.get(0);
 
-                            if(personDeviceLog.getRecordTime().compareTo(startTime.toDate())>0 && personDeviceLog.getRecordTime().compareTo(attendanceTime.toDate())<=0){
+                            //上班加1分钟
+                            if(personDeviceLog.getRecordTime().compareTo(startTime.toDate())>0 && personDeviceLog.getRecordTime().compareTo(attendanceTime.plusMinutes(1).toDate())<=0){
                                 workAttendance.setResult(WorkAttendance.SUCCESS);
                             }
-                            else if(personDeviceLog.getRecordTime().compareTo(attendanceTime.toDate())>0 && personDeviceLog.getRecordTime().compareTo(endTime.toDate())<=0){
+                            else if(personDeviceLog.getRecordTime().compareTo(attendanceTime.plusMinutes(1).toDate())>0 && personDeviceLog.getRecordTime().compareTo(endTime.toDate())<=0){
                                 workAttendance.setResult(WorkAttendance.LATE);
                             }
                         } else {
@@ -183,13 +198,14 @@ public class UnmeasureTemperatureAlarmTask {
                 }
 
                 //统计缺卡
-                recordUnAttendance(alarmConfig,startTime.toDate(),attendanceTime.toDate(),endTime.toDate(),WorkAttendance.MISSING);
+                affectCount+= recordUnAttendance(alarmConfig,startTime.toDate(),attendanceTime.toDate(),endTime.toDate(),WorkAttendance.MISSING);
             }
         }
 
         return affectCount;
     }
 
+
     private void writeDbLog(String remark,String companyId){
         SysLog sysLog = new SysLog();
         sysLog.setPointcut("未测体温提醒");
@@ -213,13 +229,17 @@ public class UnmeasureTemperatureAlarmTask {
 
         String date = now.toString("yyyy-MM-dd");
 
-        //最近一年的节假日
-        Set<String> holidaySet = holidayInfoService.getHolidaySetByDate(now.minusDays(364).toDate(),now.plusDays(1).toDate());
+
+        //最近一周的节假日
+        Set<String> holidaySet = holidayInfoService.getHolidaySetByDate(now.minusDays(7).toDate(),now.plusDays(1).toDate(),false);
 
         if (holidaySet.contains(date)){
             return;
         }
 
+        //虽然放假但正常上班
+        Map<String,HolidayInfo> fakeHolidayMap = holidayInfoService.getHolidayMapByDate(now.minusDays(7).toDate(),now.plusDays(1).toDate(),true);
+
         int weekday = now.getDayOfWeek();
 
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
@@ -242,6 +262,14 @@ public class UnmeasureTemperatureAlarmTask {
                     alarmTime = attendanceTime.plusMinutes(10);
                 }
 
+                if(fakeHolidayMap.containsKey(date)){
+                    //虽然放假但需要工作
+                    HolidayInfo holidayInfo = fakeHolidayMap.get(date);
+
+                    //参考工作日
+                    weekday = holidayInfo.getRefWeekday();
+                }
+
                 //开始时间
                 if (weekdays.indexOf(String.valueOf(weekday)) != -1) {
                     if (now.compareTo(alarmTime)>=0 && now.compareTo(alarmTime.plusMinutes(intervalMinute))<0) {