/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.sxkj.system.entity; import com.baomidou.mybatisplus.annotation.FieldStrategy; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.core.tenant.mp.TenantEntity; import org.springblade.core.tool.utils.StringUtil; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.sxkj.common.utils.ValidUtil; import java.time.LocalTime; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Objects; /** * 实体类 * * @author Chill */ @Data @TableName("blade_user") @EqualsAndHashCode(callSuper = true) public class User extends TenantEntity { private static final long serialVersionUID = 1L; private Long id; /** * 用户编号 */ private String code; /** * 用户平台 */ private Integer userType; /** * 账号 */ private String account; /** * 密码 */ private String password; /** * 昵称 */ private String name; /** * 真名 */ private String realName; /** * 头像 */ private String avatar; /** * 邮箱 */ private String email; /** * 手机 */ private String phone; /** * 生日 */ private Date birthday; /** * 性别 */ private Integer sex; /** * 角色id */ private String roleId; /** * 部门id */ private String deptId; /** * 岗位id */ private String postId; /** * 行政区划代码 */ private String areaCode; /** * 过期时间 */ @TableField(updateStrategy = FieldStrategy.ALWAYS) private Date expireTime; /** * 最大登录次数 */ @TableField(updateStrategy = FieldStrategy.ALWAYS) private Long maxLoginNum; /** * 可飞行开始时间 */ private String flightStartTime; /** * 可飞行结束时间 */ private String flightEndTime; /** * 判断用户是否过期的 * @return */ public static boolean assertUserNotExpired(Date expireTime) { if(Objects.isNull(expireTime)){ return false; } return expireTime.before(new Date()); } /** * 判断是否飞行处在飞行时间内 * true 是可以飞 * false 不能飞 * @return */ private boolean checkIsInDailyFlightTime(String time) { // 获取当前时间的小时和分钟 LocalTime now = StringUtil.isBlank(time)?LocalTime.now():LocalTime.parse(time); // 两个时间都为空,直接返回true if (StringUtils.isEmpty(flightStartTime) && StringUtils.isEmpty(flightEndTime)) { return true; } try { // 解析开始时间 LocalTime start = !StringUtils.isEmpty(flightStartTime) ? LocalTime.parse(flightStartTime) : null; // 解析结束时间 LocalTime end =!StringUtils.isEmpty(flightEndTime) ? LocalTime.parse(flightEndTime) : null; // 处理各种边界情况 if (start == null && end != null) { // 只有结束时间:当前时间 <= 结束时间 return !now.isAfter(end); } else if (start != null && end == null) { // 只有开始时间:当前时间 >= 开始时间 return !now.isBefore(start); } else if (start != null && end != null) { if (start.equals(end)) { // 开始和结束时间相同:任何时间都满足 return false; } else if (start.isBefore(end)) { // 正常时间段:开始时间 <= 当前时间 <= 结束时间 return !now.isBefore(start) && !now.isAfter(end); } else { // 跨天时间段:当前时间 >= 开始时间 或 当前时间 <= 结束时间 return !now.isBefore(start) || !now.isAfter(end); } } } catch (Exception e) { // 时间格式解析错误 throw new IllegalArgumentException("Invalid time format. Expected HH:mm"); } return true; } /** * 校验所有时间都满足条件 * @param times 事件 HH:MM * @return */ public boolean checkAllTime(List times){ if(CollectionUtils.isEmpty(times)){ return checkIsInDailyFlightTime(""); } for (String time:times){ boolean flag = checkIsInDailyFlightTime(time); if(!flag){ return false; } } return true; } }