liupeng 4 years ago
parent
commit
5a31cfd58d

BIN
code/sapparent/sapcms/src/main/webapp/public/excel/userReport.xlsx


+ 56 - 0
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapCheckMapper.xml

@@ -122,6 +122,62 @@
 		where checkinDay >= #{startDay} and checkinDay <= #{endDay}
 	</update>
 	
+	<update id="updateRealCheckinDate">
+		update sap_check_report
+		set realCheckinDate = (
+			case when checkinException not like '%未打卡' and checkinDate is not null then checkinDate
+				 when checkoutDate1 is not null and checkoutDate1 %lt; concat(checkinDay,' 13:00:00') then checkoutDate1
+				 else ''
+			end
+		)
+		where realCheckinDate is null
+	</update>
+	
+	<update id="updateRealCheckoffDate">
+		update sap_check_report
+		set realCheckoffDate = (
+			case when checkoutDate2 is not null and checkoutDate2 > concat(checkinDay,' 12:00:00') then checkoutDate2
+				 when checkoutDate1 is not null and checkoutDate1 > concat(checkinDay,' 12:00:00') then checkoutDate1
+				 when checkoffException not like '%未打卡' and checkoffDate is not null then checkoffDate
+				 else ''
+			end
+		)
+		where realCheckoffDate is null
+	</update>
+	
+	<update id="updateRealResultRemark">
+		update sap_check_report
+		set realResultRemark = concat((
+			case when realCheckinDate = '' then '上班未打卡,' 
+				 when realCheckinDate > concat(checkinDay,' ', workTime, ':00') then '迟到,'
+				 else ''
+			end
+		),(
+			case when realCheckoffDate = '' then '下班未打卡' 
+				 when realCheckoffDate %lt; concat(checkinDay,' ', offWorkTime, ':00') then '早退,'
+				 else ''
+			end
+		))
+		where realResultRemark is null
+	</update>
+	
+	<update id="updateRealResult">
+		update sap_check_report
+		set realResult = (case when length(realResultRemark) > 0 then '异常' else '正常' end)
+		where realResult is null
+	</update>
+	
+	<update id="updateWorkMins">
+		update sap_check_report
+		set workMins = (
+			case when realCheckinDate != '' and realCheckoffDate != '' 
+					then ROUND((unix_timestamp(realCheckoffDate)-unix_timestamp(realCheckinDate))/60,0)  
+				 else '' 
+			end
+		)
+		where workMins is null
+	</update>
+	
 	<select id="selectLeaveDayList" resultType="SapCheckReport">
 		SELECT * from sap_check_report where result = '异常' and leaveDay is not null 
 			and checkinDay >= #{startDay} and checkinDay &lt;= #{endDay}

+ 31 - 14
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapCheckReportMapper.xml

@@ -2,24 +2,41 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="SapCheckReportMapper">
 	<select id="selectReportDayList" resultType="java.util.LinkedHashMap">
-		SELECT c.firstDepartName,c.secondDepartName, c.userId, c.name, ${reportDaySql}
-		from wx_user c left join sap_check_report a on a.userId = c.userId 
-			and a.checkinDay >= #{startDate} and a.checkinDay &lt;= #{endDate}
-		where 1=1 
-		<if test="name != null and name != ''">
-			and a.name like CONCAT(CONCAT('%', #{name}),'%')
-		</if>
-		<if test="departId != null and departId != ''">
-			and (c.firstDepartId=#{departId} or c.secondDepartId=#{departId})
-		</if>
-		group by c.firstDepartName,c.secondDepartName, c.userId, c.name
-		order by c.userId
+		select * from 
+		(
+			SELECT c.firstDepartName,c.secondDepartName, c.userId, c.name, '状态', ${reportDaySql}
+			from wx_user c left join sap_check_report a on a.userId = c.userId 
+				and a.checkinDay >= #{startDate} and a.checkinDay &lt;= #{endDate}
+			where 1=1 
+			<if test="name != null and name != ''">
+				and a.name like CONCAT(CONCAT('%', #{name}),'%')
+			</if>
+			<if test="departId != null and departId != ''">
+				and (c.firstDepartId=#{departId} or c.secondDepartId=#{departId})
+			</if>
+			group by c.firstDepartName,c.secondDepartName, c.userId, c.name
+			union all
+			SELECT c.firstDepartName,c.secondDepartName, c.userId, c.name, '备注信息', ${reportDayRemarkSql}
+			from wx_user c left join sap_check_report a on a.userId = c.userId 
+				and a.checkinDay >= #{startDate} and a.checkinDay &lt;= #{endDate}
+			where 1=1 
+			<if test="name != null and name != ''">
+				and a.name like CONCAT(CONCAT('%', #{name}),'%')
+			</if>
+			<if test="departId != null and departId != ''">
+				and (c.firstDepartId=#{departId} or c.secondDepartId=#{departId})
+			</if>
+			group by c.firstDepartName,c.secondDepartName, c.userId, c.name
+			order by c.userId
+		) a
+		order by userId
 	</select>
 	
 	<select id="findUserReports" resultType="java.util.LinkedHashMap">
 		SELECT c.firstDepartName,c.secondDepartName,a.userId,groupName,workTime,offWorkTime,a.name,a.checkinDay,
-			checkinDate,checkinException,checkoffDate,checkoffException,checkoutDate1,checkoutDate2,leaveCreatedTime,
-			leaveStartDate,leaveEndDate,leaveDay,leaveComment,bukaDay,result
+			checkinDate,checkinException,checkoffDate,checkoffException,checkoutDate1,checkoutDate2,
+			realCheckinDate,realCheckoffDate,leaveCreatedTime,leaveStartDate,leaveEndDate,leaveDay,
+			leaveComment,bukaDay,workMins,realResult,realResultRemark
 		from sap_check_report a, sap_checkdate b, wx_user c 
 		where a.checkinDay=b.checkinDay and a.userId = c.userId
 		<if test="departId != null and departId != ''">

+ 14 - 1
code/sapparent/sapservice/src/main/java/org/fouram/service/SapCheckReportService.java

@@ -68,6 +68,7 @@ public class SapCheckReportService extends BaseService {
 		pd.put("departId", departId);
 		pd.put("name", name);
 		pd.put("reportDaySql", getReportDaySql(startDate, endDate));
+		pd.put("reportDayRemarkSql", getReportRemarkDaySql(startDate, endDate));
 
 //		公司 部门 工号	姓名5月25日	5月26日	5月27日	5月28日	5月29日
 		List<String> days = DateUtil.getSubDateList(startDate, endDate);
@@ -76,6 +77,7 @@ public class SapCheckReportService extends BaseService {
 		headerMap.put("secondDepartName", "部门");
 		headerMap.put("userId", "工号");
 		headerMap.put("name", "姓名");
+		headerMap.put("type", "类型");
 		for (String day : days) {
 			headerMap.put(day, day);
 		}
@@ -86,7 +88,18 @@ public class SapCheckReportService extends BaseService {
 	}
 
 	private String getReportDaySql(String startDate, String endDate) throws Exception {
-		String baseSql = "replace(group_concat(case when a.checkinDay = '%s' then a.result else '' end ),',','') as '%s',";
+		String baseSql = "replace(group_concat(case when a.checkinDay = '%s' then a.realResult else '' end ),',','') as '%s',";
+		List<String> days = DateUtil.getSubDateList(startDate, endDate);
+		String reportDaySql = "";
+		for (String day : days) {
+			reportDaySql += String.format(baseSql, day, day);
+		}
+		reportDaySql = reportDaySql.substring(0, reportDaySql.length() - 1);
+		return reportDaySql;
+	}
+	
+	private String getReportRemarkDaySql(String startDate, String endDate) throws Exception {
+		String baseSql = "replace(group_concat(case when a.checkinDay = '%s' then a.realResultRemark else '' end ),',','') as '%s',";
 		List<String> days = DateUtil.getSubDateList(startDate, endDate);
 		String reportDaySql = "";
 		for (String day : days) {

+ 19 - 0
code/sapparent/sapservice/src/main/java/org/fouram/service/WxCheckService.java

@@ -174,6 +174,25 @@ public class WxCheckService extends BaseService {
 		update("SapCheckMapper.updateResultOkByAllLeave", null);
 		// 更新hour字段
 		update("SapCheckMapper.updateAllHour", param);
+		// 新增列:上班时间
+		// 如“固定打卡”未打,“最早外出打卡时间”有则取“最早外出打卡时间”作为“上班时间”
+		// 如“固定打卡”or“最早外出打卡时间”都有则取“固定时间”作为“上班时间”
+		// “最早外出打卡时间”在“13:00”前才能作为“上班时间”
+		update("SapCheckMapper.updateRealCheckinDate", null);
+		// 新增列:下班时间
+		// 如有“固定打卡时间”or“最晚外出打卡时间”则取“最晚外出打卡时间”作为“下班时间”
+		// “最晚外出打卡时间”在“12:00”后才能作为“下班时间”
+		update("SapCheckMapper.updateRealCheckoffDate", null);
+		//异常信息提示
+		//1.列“上班打卡异常信息”
+		//a.当“上班时间”为空,列“上班打卡时间”置为空值(现在会显示打卡规则时间),提示“上班未打卡”
+		//b.当“上班时间”晚于打卡规则,提示“迟到”
+		//2.列“下班打卡异常信息”
+		//a.当“下班时间”为空,列“下班打卡时间”置为空值,提示“下班未打卡”
+		//b.当“下班时间”晚于打卡规则,提示“早退”
+		//增加列:“备注”,备注显示信息如下:符合多种状态逗号分割显示
+		update("SapCheckMapper.updateRealResultRemark", null);
+		update("SapCheckMapper.updateRealResult", null);
 	}
 
 	// 是不是正确的上班时间