123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #include "checkperiodfunc.h"
- #include "spdlog/spdlog.h"
- /**
- * @brief 周查重函数
- *
- * @param planList 需要查重的列表
- * @param plan 目标计划
- * @param isExcludeSelf 是否排除自身
- * @return true
- * @return false
- */
- bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan)
- {
- bool isConflict = false;
- for(const auto& it : planList)
- {
- /* info结束时间小于开始时间,或者info开始时间大于结束时间,就不冲突 */
- bool isLess = weekTimeIsGerater(it.weekType, it.timeStart, plan.weekType, plan.timeEnd);
- bool isGreater = weekTimeIsGerater(plan.weekType, plan.timeStart, it.weekType, it.timeEnd);
- if(isLess || isGreater)
- {
- /* 时间不冲突 */
- continue;
- }
- isConflict = true; /* 时间冲突 */
- break;
- }
- return isConflict;
- }
- /* 查重函数重载,排除一个计划 */
- bool isWeekPlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, const OnePlan_t& excludePlan)
- {
- QList<OnePlan_t> list = planList;
- /* 排除自身 */
- for(int i = 0; i < list.size(); ++i)
- {
- // SPDLOG_DEBUG("{}, {}-{} 与 {}, {}-{}",
- // static_cast<int>(list[i].weekType), list[i].timeStart.toString("hh:mm:ss").toStdString(), list[i].timeEnd.toString("hh:mm:ss").toStdString(),
- // static_cast<int>(excludePlan.weekType), excludePlan.timeStart.toString("hh:mm:ss").toStdString(), excludePlan.timeEnd.toString("hh:mm:ss").toStdString());
- if(list[i].weekType == excludePlan.weekType &&
- list[i].timeStart == excludePlan.timeStart && list[i].timeEnd == excludePlan.timeEnd)
- {
- list.removeAt(i);
- break;
- }
- }
- return isWeekPlanDuplicate(list, plan);
- }
- /**
- * @brief 日期查重函数
- *
- * @param planList
- * @param plan
- * @param isExcludeSelf
- * @return true
- * @return false
- */
- bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan)
- {
- bool isConflict = false;
- for(const auto& it : planList)
- {
- /* info结束时间小于开始时间,或者info开始时间大于结束时间,就不冲突 */
- bool isLess = dateTimeIsGerater(it.date, it.timeStart, plan.date, plan.timeEnd);
- bool isGreater = dateTimeIsGerater(plan.date, plan.timeStart, it.date, it.timeEnd);
- if(isLess || isGreater)
- {
- /* 时间不冲突 */
- continue;
- }
- isConflict = true; /* 时间冲突 */
- break;
- }
- return isConflict;
- }
- /* 日期查重,重载版,排除一个日期计划 */
- bool isDatePlanDuplicate(const QList<OnePlan_t>& planList, const OnePlan_t& plan, const OnePlan_t& excludePlan)
- {
- QList<OnePlan_t> list = planList;
- /* 排除自身 */
- for(int i = 0; i < list.size(); ++i)
- {
- if(list[i].date == excludePlan.date &&
- list[i].timeStart == excludePlan.timeStart && list[i].timeEnd == excludePlan.timeEnd)
- {
- list.removeAt(i);
- break;
- }
- }
-
- return isDatePlanDuplicate(list, plan);
- }
- /* 周时间1大于周时间2 */
- bool weekTimeIsGerater(const eWeekType& week1, const QTime& time1,
- const eWeekType& week2, const QTime& time2)
- {
- /* 先比较日期 */
- if(week1 > week2)
- {
- return true;
- }
- else if(week1 == week2)
- {
- /* 日期相同,比较时间 */
- if(time1 > time2)
- {
- return true;
- }else
- {
- return false;
- }
- }
- return false;
-
- }
- /* 日期1大于日期2 */
- bool dateTimeIsGerater(const QDate& date1, const QTime& time1,
- const QDate& date2, const QTime& time2)
- {
- /* 先比较日期 */
- if(date1 > date2)
- {
- return true;
- }
- else if(date1 == date2)
- {
- /* 日期相同,比较时间 */
- if(time1 > time2)
- {
- return true;
- }else
- {
- return false;
- }
- }
- return false;
- }
|