Browse Source

排班接口增加重复提交控制。

zhengqiang 3 năm trước cách đây
mục cha
commit
9e9915a2ac

+ 3 - 1
common/src/main/java/com/jpsoft/shinestar/modules/base/dao/WorkPersonSchedulingDAO.java

@@ -23,7 +23,7 @@ public interface WorkPersonSchedulingDAO {
 
 	int deleteByPersonIdSchedulingDay(int year, int month, int day, Long personId);
 
-    WorkPersonScheduling findByPersonIdSchedulingDay(Long personId, Date dateTime);
+    List<WorkPersonScheduling> findByPersonIdSchedulingDay(Long personId, Date dateTime);
 
 	List<WorkPersonScheduling> findByPersonIdYearMonth(Long personId,int year,int month);
 
@@ -34,4 +34,6 @@ public interface WorkPersonSchedulingDAO {
 	List<Date> findSchedulingDayByPersonIdSDateAndEDate(Long personId,Date startDate,Date endDate,boolean isQueryRest);
 
 	List<Date> findRepeatSchedulingDay(Long personId);
+
+	List<Map> findRedundantSchedule(Date startDate,Date endDate);
 }

+ 19 - 7
common/src/main/java/com/jpsoft/shinestar/modules/base/service/impl/WorkPersonSchedulingServiceImpl.java

@@ -85,7 +85,14 @@ public class WorkPersonSchedulingServiceImpl implements WorkPersonSchedulingServ
 
 	@Override
 	public WorkPersonScheduling findByPersonIdSchedulingDay(Long personId, Date dateTime) {
-		return workPersonSchedulingDAO.findByPersonIdSchedulingDay(personId,dateTime);
+		List<WorkPersonScheduling> list = workPersonSchedulingDAO.findByPersonIdSchedulingDay(personId,dateTime);
+
+		if(list.size()>0){
+			return list.get(0);
+		}
+		else{
+			return null;
+		}
 	}
 
 	@Override
@@ -143,12 +150,17 @@ public class WorkPersonSchedulingServiceImpl implements WorkPersonSchedulingServ
 		List<Date> schedulingDays =  workPersonSchedulingDAO.findRepeatSchedulingDay(personId);
 		int count = 0;
 		for(Date schedulingDay :schedulingDays) {
-			WorkPersonScheduling wps = workPersonSchedulingDAO.findByPersonIdSchedulingDay(personId,schedulingDay);
-			wps.setDelFlag(true);
-			wps.setUpdateBy("批量操作");
-			wps.setUpdateTime(new Date());
-			int a = workPersonSchedulingDAO.update(wps);
-			count = count + a;
+			List<WorkPersonScheduling> list = workPersonSchedulingDAO.findByPersonIdSchedulingDay(personId,schedulingDay);
+
+			if(list.size()>0){
+				WorkPersonScheduling wps = list.get(0);
+
+				wps.setDelFlag(true);
+				wps.setUpdateBy("批量操作");
+				wps.setUpdateTime(new Date());
+				int a = workPersonSchedulingDAO.update(wps);
+				count = count + a;
+			}
 		}
 		return count;
 	}

+ 19 - 1
common/src/main/resources/mapper/base/WorkPersonScheduling.xml

@@ -143,7 +143,6 @@
 		where del_flag = 0
 		and person_id = #{personId}
 		and scheduling_day = #{dateTime}
-		limit 1
 		]]>
 	</select>
 
@@ -241,4 +240,23 @@
 		ORDER BY
 			scheduling_day ASC
 	</select>
+	<select id="findRedundantSchedule" resultType="map">
+		<![CDATA[
+			select * from (
+				select
+				person_id as personId,
+				scheduling_day as schedulingDay,
+				count(*) as total
+				from base_work_person_scheduling
+				where
+				scheduling_day>=#{startDate}
+				and
+				scheduling_day<=#{endDate}
+				and
+				del_flag=0
+				group by person_id,scheduling_day
+			) as a
+			where a.total>1
+		]]>
+	</select>
 </mapper>

+ 8 - 0
web/src/main/java/com/jpsoft/shinestar/modules/base/controller/WorkPersonSchedulingController.java

@@ -380,6 +380,9 @@ public class WorkPersonSchedulingController {
             HttpServletRequest request) throws Exception{
         MessageResult<List> msgResult = new MessageResult<>();
 
+        if(!valueOperations.setIfAbsent("changeScheduling_" + subject,true,3,TimeUnit.SECONDS)){
+            throw new Exception("操作过于频繁,请稍后再试!");
+        }
 
         Map<String,Object> searchParams = new HashMap<>();
         if (StringUtils.isNotEmpty(companyId)) {
@@ -389,6 +392,7 @@ public class WorkPersonSchedulingController {
         }else{
             throw new Exception("请选择部门");
         }
+
         List<Sort> sortList = new ArrayList<>();
         sortList.add(new Sort("b.sort_no","asc"));
         sortList.add(new Sort("a.id_","asc"));
@@ -531,6 +535,10 @@ public class WorkPersonSchedulingController {
         MessageResult<String> msgResult = new MessageResult<>();
 
         try {
+            if(!valueOperations.setIfAbsent("changePersonShift_" + subject,true,3,TimeUnit.SECONDS)){
+                throw new Exception("操作过于频繁,请稍后再试!");
+            }
+
             PersonInfo personInfo = personInfoService.get(Long.valueOf(personId));
             if(personInfo == null){
                 throw new Exception("未找到用户");

+ 58 - 0
web/src/test/java/com/jpsoft/shinestar/WorkPersonSchedulingTest.java

@@ -0,0 +1,58 @@
+package com.jpsoft.shinestar;
+
+import com.jpsoft.shinestar.modules.base.dao.WorkPersonSchedulingDAO;
+import com.jpsoft.shinestar.modules.base.entity.WorkPersonScheduling;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class WorkPersonSchedulingTest {
+    @Autowired
+    private WorkPersonSchedulingDAO workPersonSchedulingDAO;
+
+    @Transactional
+    private void innerUpdate(){
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+        try {
+            Date startDate = sdf.parse("2021-09-01");
+            Date endDate = sdf.parse("2021-09-30");
+
+            List<Map> mapList = workPersonSchedulingDAO.findRedundantSchedule(startDate,endDate);
+
+            for (Map map : mapList) {
+                Long personId = Long.valueOf(map.get("personId").toString());
+                Date schedulingDay = (Date)map.get("schedulingDay");
+
+                List<WorkPersonScheduling> list = workPersonSchedulingDAO.findByPersonIdSchedulingDay(personId,schedulingDay);
+
+                if (list.size()>1){
+                    WorkPersonScheduling wps = list.get(list.size()-1);
+                    wps.setDelFlag(true);
+                    wps.setUpdateTime(new Date());
+
+                    workPersonSchedulingDAO.update(wps);
+                }
+            }
+
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    public void testUpdate(){
+        innerUpdate();
+    }
+}