a
554325746@qq.com
2020-01-10 ce0902f1721b9de6c0a2e8b16cdb6be2c6bca2b3
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
package com.basic.security.manager;
 
import android.text.TextUtils;
 
import com.basic.security.model.ModelAdapter;
import com.basic.security.utils.ExceptionUtil;
 
import java.util.ArrayList;
import java.util.List;
 
public class BusinessPersonManager extends BaseManager {
    public static void savePersonToBusiness(String personId, String businessId, String passModel) {
        ModelAdapter businessPersonDocument = findOne("select * from business_person where business_id='" + businessId + "' and person_id='" + personId + "'");
        if (businessPersonDocument == null) {
            businessPersonDocument = new ModelAdapter();
        }
        businessPersonDocument.setString("person_id", personId);
        businessPersonDocument.setString("business_id", businessId);
        businessPersonDocument.setString("pass_model", passModel);
        businessPersonDocument.setString("table", "business_person");
        save(businessPersonDocument);
    }
 
    public static List<ModelAdapter> getPersonFromBusiness(String businessId) {
        List<ModelAdapter> businessPersonListDocument = findList("select * from business_person where del_flag='0' and business_id='" + businessId + "' ");
        List<ModelAdapter> personList = new ArrayList<>();
        if (businessPersonListDocument.size() != 0) {
            for (ModelAdapter businessPerson : businessPersonListDocument) {
                ModelAdapter person = findById("person", businessPerson.getString("person_id"));
                if (person != null) {
                    if (!personList.contains(person)) {
                        personList.add(person);
                    } else {
                        deletePhysically(businessPerson);
                    }
                }
            }
            return personList;
        }
        return new ArrayList<>();
    }
 
    public static String getPersonInBusinessPassModel(String businessId, String personId) {
        ModelAdapter businessPerson = findOne("select * from business_person where business_id='" + businessId + "' and person_id='" + personId + "' ");
        return businessPerson.getString("pass_model") == null ? "有效时间内通行" : businessPerson.getString("pass_model");
    }
 
    public static void deleteBusinessPerson(String personId, String businessId) {
        try {
            List<ModelAdapter> personList = findList("select * from business_person where business_id='" + businessId + "' and person_id='" + personId + "'");
            for (ModelAdapter person : personList) {
                deletePhysically(person);
            }
        } catch (Exception e) {
            ExceptionUtil.printException(e);
        }
    }
 
    public static List<ModelAdapter> getPersonFromMessage(List<ModelAdapter> checkedAllPerson, String searchText) {
        if (checkedAllPerson.size() != 0) {
            List<ModelAdapter> personFromMessage = new ArrayList<>();
            for (ModelAdapter person : checkedAllPerson) {
                String person_name = person.getString("name");
                String person_phone = person.getString("phone");
                String person_id_card = person.getString("id_card_number");
                if (searchText.equals(person_id_card) || searchText.equals(person_name) || searchText.equals(person_phone)) {
                    if (person != null) {
                        personFromMessage.add(person);
                    }
                }
            }
            return personFromMessage;
        }
        return new ArrayList<>();
    }
 
    public static List<ModelAdapter> getValidBusinessRuleList() {
        List<ModelAdapter> validBusinessRuleList = new ArrayList<>();
        List<ModelAdapter> businessRuleList = BusinessListManager.getBusinessList();
        for (ModelAdapter businessRule : businessRuleList) {
            if ("1".equals(businessRule.getString("only_allow"))) {
                String only_allow_start = businessRule.getString("only_allow_start");
                String only_allow_end = businessRule.getString("only_allow_end");
                long start_time = Long.parseLong(only_allow_start);
                long end_time = Long.parseLong(only_allow_end);
                if (System.currentTimeMillis() > start_time && System.currentTimeMillis() < end_time) {
                    validBusinessRuleList.add(businessRule);
                }
            } else if ("1".equals(businessRule.getString("choose_from_time_rule"))) {
                if (TimeRuleManager.timeRuleIsValid(businessRule.getString("checked_time_rule_id"))) {
                    validBusinessRuleList.add(businessRule);
                }
            }
        }
        return validBusinessRuleList;
    }
 
    public static List<ModelAdapter> getPersonInValidBusinessList(String personId) {
        List<ModelAdapter> personInValidBusinessList = new ArrayList<>();
        List<ModelAdapter> validBusinessRuleList = getValidBusinessRuleList();
        for (ModelAdapter validBusinessRule : validBusinessRuleList) {
            ModelAdapter person = findOne("select * from business_person where business_id='" + validBusinessRule.getId() + "' and person_id='" + personId + "' ");
            if (person != null) {
                System1.out.println(person.getString("pass_model"));
            }
            if (person != null && "有效时间内通行".equals(person.getString("pass_model"))) {
                personInValidBusinessList.add(validBusinessRule);
            }
        }
        return personInValidBusinessList;
    }
 
    public static List<ModelAdapter> getValidBusinessRuleListButTimeNotReach() {
        List<ModelAdapter> validBusinessRuleButNotReachList = new ArrayList<>();
        List<ModelAdapter> businessList = BusinessListManager.getBusinessList();
        for (ModelAdapter businessRule : businessList) {
            long noReachTime = BusinessDetailManager.getNotReachRemindTime(businessRule.getId());
            if ("1".equals(businessRule.getString("only_allow"))) {
                String only_allow_start = businessRule.getString("only_allow_start");
                String only_allow_end = businessRule.getString("only_allow_end");
                long start_time = Long.parseLong(only_allow_start);
                long end_time = Long.parseLong(only_allow_end);
                if (System.currentTimeMillis() + noReachTime * 60 * 1000 > start_time && System.currentTimeMillis() < end_time) {
                    validBusinessRuleButNotReachList.add(businessRule);
                }
            } else if ("1".equals(businessRule.getString("choose_from_time_rule"))) {
                if (TimeRuleManager.timeRuleIsValid(businessRule.getString("checked_time_rule_id"), noReachTime * 60 * 1000)) {
                    validBusinessRuleButNotReachList.add(businessRule);
                }
            }
        }
        return validBusinessRuleButNotReachList;
    }
 
    public static List<ModelAdapter> getValidBusinessRuleListButTimeNotReach(String personId) {
        List<ModelAdapter> personInValidBusinessRuleButNotReachList = new ArrayList<>();
        List<ModelAdapter> validBusinessRuleListButTimeNotReach = getValidBusinessRuleListButTimeNotReach();
        for (ModelAdapter notReachBusinessRule : validBusinessRuleListButTimeNotReach) {
            ModelAdapter person = findOne("select * from business_person where business_id='" + notReachBusinessRule.getId() + "' and person_id='" + personId + "'");
            if (person != null && "有效时间内通行".equals(person.getString("pass_model"))) {
                personInValidBusinessRuleButNotReachList.add(notReachBusinessRule);
            }
        }
        return personInValidBusinessRuleButNotReachList;
    }
 
    public static String getBusinessRuleDoorAccessConfirmMessage(ModelAdapter document, ModelAdapter currentPerson) {
        String message = "";
        if (BusinessDetailManager.getConfirmPassShowIdentity(document.getId())) {
            List<String> identityNameList = PersonIdentityManager.findIdentityNameByPersonId(currentPerson.getId());
            if (identityNameList.size() != 0) {
                message = identityNameList.get(0);
            }
        }
        if (BusinessDetailManager.getConfirmPassShowName(document.getId())) {
            message = message + "  " + currentPerson.getString("name");
        }
        String confirmPassHint = BusinessDetailManager.getConfirmPassHint(document.getId());
        if (!TextUtils.isEmpty(confirmPassHint)) {
            message = message + "  " + confirmPassHint;
        }
        if (TextUtils.isEmpty(message)) {
            return "业务表:确认通行";
        }
        return message;
    }
 
    public static String getBusinessRuleDoorAccessAllowMessage(ModelAdapter document, ModelAdapter currentPerson) {
        String message = "";
        if (BusinessDetailManager.getAccessShowTableName(document.getId())) {
            if (!TextUtils.isEmpty(document.getString("business_name"))) {
                message = document.getString("business_name");
            }
        }
        if (BusinessDetailManager.getAccessShowIdentity(document.getId())) {
            List<String> identityNameList = PersonIdentityManager.findIdentityNameByPersonId(currentPerson.getId());
            if (identityNameList.size() != 0) {
                message = message + "  " + identityNameList.get(0);
            }
        }
        if (BusinessDetailManager.getAccessShowName(document.getId())) {
            message = message + "  " + currentPerson.getString("name");
        }
        String accessHint = BusinessDetailManager.getAccessHint(document.getId());
        if (!TextUtils.isEmpty(accessHint)) {
            message = message + "  " + accessHint;
        }
        if (TextUtils.isEmpty(message)) {
            return "业务表:允许通行";
        }
        return message;
    }
 
    public static String getBusinessDoorAccessTimeNotReachMessage(ModelAdapter currentValidBusinessRuleListButTimeNotReach, ModelAdapter currentPerson) {
        String notReachHint = BusinessDetailManager.getNotReachHint(currentValidBusinessRuleListButTimeNotReach.getId());
        if (!TextUtils.isEmpty(notReachHint)) {
            return notReachHint;
        }
        return "业务表:时间未到";
    }
}