Pārlūkot izejas kodu

同一事项同一天同一乐团不能有重复安排

周箭河 4 gadi atpakaļ
vecāks
revīzija
f2e7c60b6b

+ 7 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/InspectionItemPlanDao.java

@@ -25,4 +25,11 @@ public interface InspectionItemPlanDao extends BaseDAO<Long, InspectionItemPlan>
      * @return
      */
     InspectionItemPlan getPlanInfo(@Param("id") Long id);
+
+    /**
+     * 获取事项时间段内乐团的计划数
+     *
+     * @return
+     */
+    int getMusicGroupItemPlanCount(@Param("itemId") Long itemId, @Param("musicGroupId") String musicGroupId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
 }

+ 8 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/InspectionItemPlanServiceImpl.java

@@ -87,6 +87,13 @@ public class InspectionItemPlanServiceImpl extends BaseServiceImpl<Long, Inspect
         if (itemEndTime.before(inspectionItemPlan.getPlanEnd())) {
             throw new BizException("日程时间不能晚于工作周期结束时间");
         }
+        //事项计划同一乐团同一天不能重复
+        Date dayStartTime = DateUtil.trunc(inspectionItemPlan.getPlanStart());
+        Date dayEndTime = DateUtil.trunc(inspectionItemPlan.getPlanStart());
+        int dayMusicGroupItemPlanCount = inspectionItemPlanDao.getMusicGroupItemPlanCount(inspectionItemPlan.getItemId(), inspectionItemPlan.getMusicGroupId(), dayStartTime, dayEndTime);
+        if(dayMusicGroupItemPlanCount > 0){
+            throw new BizException("该乐团当天已有巡查安排,请核查");
+        }
         //获取乐团教学点的GPS信息
         MusicGroup musicGroup = musicGroupDao.get(inspectionItemPlan.getMusicGroupId());
         School school = schoolDao.get(musicGroup.getSchoolId());
@@ -154,7 +161,7 @@ public class InspectionItemPlanServiceImpl extends BaseServiceImpl<Long, Inspect
         Date nowDate = new Date();
         Date startTime = DateUtil.getFirstDayOfMonth(nowDate);
         Date endTime = DateUtil.getLastTimeWithDay(DateUtil.getLastDayOfMonth(nowDate));
-        List<InspectionItemPlan> startPlans = inspectionItemPlanDao.getStartPlan(startTime,endTime);
+        List<InspectionItemPlan> startPlans = inspectionItemPlanDao.getStartPlan(startTime, endTime);
         Set<Integer> userIds = startPlans.stream().map(InspectionItemPlan::getUserId).collect(Collectors.toSet());
         //发送推送信息
         Map<Integer, String> userMap = new HashMap<>();

+ 13 - 1
mec-biz/src/main/resources/config/mybatis/InspectionItemPlanMapper.xml

@@ -184,7 +184,8 @@
         FROM inspection_item_plan
         WHERE plan_start_ >= #{startTime}
           AND plan_start_ <= #{endTime}
-        ]]></select>
+        ]]>
+    </select>
 
     <select id="getPlanInfo" resultMap="InspectionItemPlan">
         SELECT iip.*, su.real_name_ realName, o.name_ organName, co.name_ cooperationName, mg.name_ musicGroupName
@@ -195,4 +196,15 @@
                  LEFT JOIN music_group mg ON mg.id_ = iip.music_group_id_
         WHERE iip.id_ = #{id}
     </select>
+
+    <select id="getMusicGroupItemPlanCount" resultType="int">
+        <![CDATA[
+        SELECT COUNT(*)
+        FROM inspection_item_plan
+        WHERE music_group_id_ = #{musicGroupId}
+          AND item_id_ = #{itemId}
+          AND plan_start_ >= #{startTime}
+          AND plan_start_ <= #{endTime}
+        ]]>
+    </select>
 </mapper>