liupeng преди 5 години
родител
ревизия
25507e2f43

+ 11 - 39
code/sapparent/sapcms/src/main/java/org/fouram/controller/TaskController.java

@@ -77,14 +77,17 @@ public class TaskController extends BaseController {
 	}
 	
 	/**
-	 * http://localhost:8080/sapcms/task/saveAllUserCheckData
+	 * http://localhost:8080/sapcms/task/saveReportBaseData
 	 * @return
 	 */
-	@RequestMapping(value = "/saveAllUserCheckData", produces = "application/json;charset=utf-8")
+	@RequestMapping(value = "/saveReportBaseData", produces = "application/json;charset=utf-8")
 	@ResponseBody
-	public Object saveAllUserCheckData() {
+	public Object saveReportBaseData() {
 		try {
 			sapCheckService.saveAllUserCheckData();
+			sapCheckService.saveCheckoutStartAndEndData();
+			employeeTimeService.saveEmployeeTimes();
+//			sapCheckService.updateReportData();
 			return AppUtil.success();
 		} catch (Exception e) {
 			LoggerUtil.error(e);
@@ -93,30 +96,15 @@ public class TaskController extends BaseController {
 	}
 	
 	/**
-	 * http://localhost:8080/sapcms/task/saveAllUserCheckOption
-	 * @return
-	 */
-	@RequestMapping(value = "/saveAllUserCheckOption", produces = "application/json;charset=utf-8")
-	@ResponseBody
-	public Object saveAllUserCheckOption() {
-		try {
-			sapCheckService.saveAllUserCheckOption();
-			return AppUtil.success();
-		} catch (Exception e) {
-			LoggerUtil.error(e);
-			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
-		}
-	}
-	
-	/**
-	 * http://localhost:8080/sapcms/task/saveEmployeeTimes
+	 * http://localhost:8080/sapcms/task/saveReportResultData
 	 * @return
 	 */
-	@RequestMapping(value = "/saveEmployeeTimes", produces = "application/json;charset=utf-8")
+	@RequestMapping(value = "/saveReportResultData", produces = "application/json;charset=utf-8")
 	@ResponseBody
-	public Object saveEmployeeTimes() {
+	public Object saveReportResultData() {
 		try {
-			employeeTimeService.saveEmployeeTimes();
+			sapCheckService.updateReportBaseData();
+			sapCheckService.saveReportResultData();
 			return AppUtil.success();
 		} catch (Exception e) {
 			LoggerUtil.error(e);
@@ -139,20 +127,4 @@ public class TaskController extends BaseController {
 			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
 		}
 	}
-	
-	/**
-	 * http://localhost:8080/sapcms/task/updateReportData
-	 * @return
-	 */
-	@RequestMapping(value = "/updateReportData", produces = "application/json;charset=utf-8")
-	@ResponseBody
-	public Object updateReportData() {
-		try {
-			sapCheckService.updateReportData();
-			return AppUtil.success();
-		} catch (Exception e) {
-			LoggerUtil.error(e);
-			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
-		}
-	}
 }

+ 1 - 0
code/sapparent/sapservice/src/main/java/org/fouram/entity/SapCheck.java

@@ -18,6 +18,7 @@ import lombok.NoArgsConstructor;
 public class SapCheck implements Serializable {
 	private static final long serialVersionUID = 1L;
 
+	private Long id;
 	private String userId;
 	private String groupName;
 	private String checkinType;

+ 84 - 4
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapCheckMapper.xml

@@ -1,28 +1,72 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="SapCheckMapper">
+	<update id="truncateCheckin">
+		truncate table sap_checkin
+	</update>
 	<insert id="saveCheckin">
 		insert into sap_checkin(userId,groupName,checkinType,checkinDate,checkinDay,exceptionType,
 			checkinTime,locationTitle,locationDetail,wifiName,wifiMac) 
 		values (#{userId},#{groupName},#{checkinType},#{checkinDate},#{checkinDay},#{exceptionType},
 			#{checkinTime},#{locationTitle},#{locationDetail},#{wifiName},#{wifiMac})
 	</insert>
-	
+	<update id="truncateCheckoff">
+		truncate table sap_checkoff
+	</update>
 	<insert id="saveCheckoff">
 		insert into sap_checkoff(userId,groupName,checkinType,checkinDate,checkinDay,exceptionType,
 			checkinTime,locationTitle,locationDetail,wifiName,wifiMac) 
 		values (#{userId},#{groupName},#{checkinType},#{checkinDate},#{checkinDay},#{exceptionType},
 			#{checkinTime},#{locationTitle},#{locationDetail},#{wifiName},#{wifiMac})
 	</insert>
-	
+	<update id="truncateCheckout">
+		truncate table sap_checkout
+	</update>
 	<insert id="saveCheckout">
 		insert into sap_checkout(userId,groupName,checkinType,checkinDate,checkinDay,exceptionType,
 			checkinTime,locationTitle,locationDetail,wifiName,wifiMac) 
 		values (#{userId},#{groupName},#{checkinType},#{checkinDate},#{checkinDay},#{exceptionType},
 			#{checkinTime},#{locationTitle},#{locationDetail},#{wifiName},#{wifiMac})
 	</insert>
-	
-		
+	<update id="truncateCheckoutStart">
+		truncate table sap_checkout_start
+	</update>
+	<insert id="saveCheckoutStart1">
+		insert into sap_checkout_start
+		SELECT a.* from sap_checkout a, (SELECT userId, checkinDay from sap_checkout GROUP BY userId, checkinDay having count(1) = 1) b
+		where a.userId = b.userId and a.checkinDay = b.checkinDay 
+	</insert>
+	<insert id="saveCheckoutStart2">
+		insert into sap_checkout_start
+		SELECT a.* from sap_checkout a, (SELECT userId, checkinDay,min(checkinDate) as checkinDate from sap_checkout GROUP BY userId, checkinDay having count(1) > 1) b
+		where a.userId = b.userId and a.checkinDay = b.checkinDay and a.checkinDate = b.checkinDate ORDER BY a.userId, a.checkinDay, a.checkinDate;
+	</insert>
+	<update id="truncateCheckoutEnd">
+		truncate table sap_checkout_end
+	</update>
+	<insert id="saveCheckoutEnd">
+		insert into sap_checkout_end
+		SELECT a.* from sap_checkout a, (SELECT userId, checkinDay,max(checkinDate) as checkinDate from sap_checkout GROUP BY userId, checkinDay having count(1) > 1) b
+		where a.userId = b.userId and a.checkinDay = b.checkinDay and a.checkinDate = b.checkinDate ORDER BY a.userId, a.checkinDay, a.checkinDate;
+	</insert>
+	<update id="truncateCheckReport">
+		truncate table sap_check_report
+	</update>
+	<insert id="saveCheckReport">
+		insert into sap_check_report(userId,groupName,workTime,offWorkTime,name,checkinDay,checkinDate,checkinException,checkoffDate,checkoffException,
+			checkoutDate1,checkoutDate2,leaveCreatedTime,leaveStartDate,leaveEndDate,leaveDay,leaveComment,result)
+		select a.userId,c.groupName,'9:30','18:30',a.`name`,b.checkinDay, c.checkinDate as checkinDate,c.exceptionType as checkinException,
+			d.checkinDate as checkoffDate,d.exceptionType as checkoffException,e.checkinDate as checkoutDate1,g.checkinDate as checkoutDate2,
+			f.createdDateTime as leaveCreatedTime, f.startDate as leaveStartDate,
+			f.endDate as leaveEndDate,f.deductionQuantity as leaveDay,f.`comment` as leaveComment, '正常' as result
+		from sap_user a join sap_checkdate b on a.result = 'SUCCESS' and a.isPrimary = 1 and a.delFlag = 0 and b.weekday = 1
+		LEFT JOIN sap_checkin c on a.userId = c.userId and b.checkinDay = c.checkinDay
+		LEFT JOIN sap_checkoff d on a.userId = d.userId and b.checkinDay = d.checkinDay
+		LEFT JOIN sap_checkout_start e on a.userId = e.userId and b.checkinDay = e.checkinDay
+		LEFT JOIN sap_checkout_end g on a.userId = g.userId and b.checkinDay = g.checkinDay
+		LEFT JOIN sap_employee_time f on a.userId = f.userId and b.checkinDay = f.startDate and f.approvalStatus = 'APPROVED'
+		order by a.sortNumber ASC, b.checkinDay asc;
+	</insert>
 	<insert id="saveCheckinOption">
 		insert into sap_checkin_option(userId,workSec,offWorkSec,workTime,offWorkTime) 
 		values (#{userId},#{workSec},#{offWorkSec},#{workTime},#{offWorkTime})
@@ -48,4 +92,40 @@
 	<select id="selectCheckoutList" resultType="SapCheckReport">
 		SELECT * from sap_check_report where result = '异常' and checkoutDate1 is not null;
 	</select>
+	
+	<select id="selectRepeatCheckin" resultType="SapCheck">
+		SELECT a.* from sap_checkin a, (SELECT userId, checkinDay from sap_checkin GROUP BY userId, checkinDay having count(1) > 1) b
+		where a.userId = b.userId and a.checkinDay = b.checkinDay order by a.exceptionType, a.checkinDate;
+	</select>
+	
+	<select id="selectRepeatCheckoff" resultType="SapCheck">
+		SELECT a.* from sap_checkoff a, (SELECT userId, checkinDay from sap_checkoff GROUP BY userId, checkinDay having count(1) > 1) b
+		where a.userId = b.userId and a.checkinDay = b.checkinDay order by a.exceptionType, a.checkinDate;
+	</select>
+	
+	<select id="selectRepeatCheckoutStart" resultType="SapCheck">
+		SELECT a.* from sap_checkout_start a, (SELECT userId, checkinDay from sap_checkout_start GROUP BY userId, checkinDay having count(1) > 1) b
+		where a.userId = b.userId and a.checkinDay = b.checkinDay order by a.exceptionType, a.checkinDate;
+	</select>
+		
+	<select id="selectRepeatCheckoutEnd" resultType="SapCheck">
+		SELECT a.* from sap_checkout_end a, (SELECT userId, checkinDay from sap_checkout_end GROUP BY userId, checkinDay having count(1) > 1) b
+		where a.userId = b.userId and a.checkinDay = b.checkinDay order by a.exceptionType, a.checkinDate;
+	</select>
+	
+	<update id="deleteCheckin">
+		delete from sap_checkin where id = #{id}
+	</update>
+	
+	<update id="deleteCheckoff">
+		delete from sap_checkoff where id = #{id}
+	</update>
+	
+	<update id="deleteCheckoutStart">
+		delete from sap_checkout_start where id = #{id}
+	</update>
+	
+	<update id="deleteCheckoutEnd">
+		delete from sap_checkout_end where id = #{id}
+	</update>
 </mapper>

+ 63 - 1
code/sapparent/sapservice/src/main/java/org/fouram/service/SapCheckService.java

@@ -4,6 +4,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.commons.lang3.StringUtils;
 import org.fouram.core.base.service.BaseService;
@@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 
 import me.chanjar.weixin.cp.bean.WxCpCheckinData;
 import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
@@ -52,6 +54,11 @@ public class SapCheckService extends BaseService {
 	}
 
 	public void saveAllUserCheckData() throws Exception {
+		// 清空表记录
+		update("SapCheckMapper.truncateCheckin", null);
+		update("SapCheckMapper.truncateCheckoff", null);
+		update("SapCheckMapper.truncateCheckout", null);
+		
 		List<SapUser> users = userService.selectSuccessList();
 		Map<String, List<String>> map = groupList(users);
 		int count = 0;
@@ -82,6 +89,14 @@ public class SapCheckService extends BaseService {
 			System.out.println(count);
 		}
 	}
+	
+	public void saveCheckoutStartAndEndData() throws Exception {
+		update("SapCheckMapper.truncateCheckoutStart", null);
+		update("SapCheckMapper.truncateCheckoutEnd", null);
+		update("SapCheckMapper.saveCheckoutStart1", null);
+		update("SapCheckMapper.saveCheckoutStart2", null);
+		update("SapCheckMapper.saveCheckoutEnd", null);
+	}
 
 	public void saveAllUserCheckOption() throws Exception {
 		List<SapUser> users = userService.selectSuccessList();
@@ -132,7 +147,54 @@ public class SapCheckService extends BaseService {
 	}
 
 	@SuppressWarnings("unchecked")
-	public void updateReportData() throws Exception {
+	public void updateReportBaseData() throws Exception {
+		//处理重复数据
+		List<SapCheck> sapChecks = (List<SapCheck>) findList("SapCheckMapper.selectRepeatCheckin", null);
+		Set<String> checkinDays = Sets.newHashSet();
+		for(SapCheck sapCheck : sapChecks) {
+			if(!checkinDays.contains(sapCheck.getCheckinDay() + sapCheck.getUserId())) {
+				checkinDays.add(sapCheck.getCheckinDay() + sapCheck.getUserId());
+			} else {
+				update("SapCheckMapper.deleteCheckin", sapCheck);
+			}
+		}
+		
+		sapChecks = (List<SapCheck>) findList("SapCheckMapper.selectRepeatCheckoff", null);
+		checkinDays = Sets.newHashSet();
+		for(SapCheck sapCheck : sapChecks) {
+			if(!checkinDays.contains(sapCheck.getCheckinDay() + sapCheck.getUserId())) {
+				checkinDays.add(sapCheck.getCheckinDay() + sapCheck.getUserId());
+			} else {
+				update("SapCheckMapper.deleteCheckoff", sapCheck);
+			}
+		}
+		
+		sapChecks = (List<SapCheck>) findList("SapCheckMapper.selectRepeatCheckoutStart", null);
+		checkinDays = Sets.newHashSet();
+		for(SapCheck sapCheck : sapChecks) {
+			if(!checkinDays.contains(sapCheck.getCheckinDay() + sapCheck.getUserId())) {
+				checkinDays.add(sapCheck.getCheckinDay() + sapCheck.getUserId());
+			} else {
+				update("SapCheckMapper.deleteCheckoutStart", sapCheck);
+			}
+		}
+		
+		sapChecks = (List<SapCheck>) findList("SapCheckMapper.selectRepeatCheckoutEnd", null);
+		checkinDays = Sets.newHashSet();
+		for(SapCheck sapCheck : sapChecks) {
+			if(!checkinDays.contains(sapCheck.getCheckinDay() + sapCheck.getUserId())) {
+				checkinDays.add(sapCheck.getCheckinDay() + sapCheck.getUserId());
+			} else {
+				update("SapCheckMapper.deleteCheckoutEnd", sapCheck);
+			}
+		}
+	}
+	
+	@SuppressWarnings("unchecked")
+	public void saveReportResultData() throws Exception {
+		// 生成报表数据
+		update("SapCheckMapper.truncateCheckReport", null);
+		update("SapCheckMapper.saveCheckReport", null);
 		// 更新华人时代人员上班时间可以推迟30分钟
 		update("SapCheckMapper.updateHrsdWorkTime", null);
 		// 更新所有异常事件的数据为异常数据