吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 *      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<String> times){
        if(CollectionUtils.isEmpty(times)){
            return checkIsInDailyFlightTime("");
        }
        for (String time:times){
            boolean flag = checkIsInDailyFlightTime(time);
            if(!flag){
                return false;
            }
        }
        return true;
    }
 
 
 
 
 
}