package com.basic.security.manager; import android.text.TextUtils; import com.basic.security.model.ModelAdapter; 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 getPersonFromBusiness(String businessId) { List businessPersonListDocument = findList("select * from business_person where del_flag='0' and business_id='" + businessId + "' "); // 业务表中所有人 List personList = new ArrayList<>(); // 根据业务表中的所有人的人员ID获取到 数据库中的人员 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<>(); } // 根据业务表Id,人员id获取人员的通行规则 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 personList = findList("select * from business_person where business_id='" + businessId + "' and person_id='" + personId + "'"); for (ModelAdapter person : personList) { deletePhysically(person); } } catch (Exception e) { e.printStackTrace(); } } public static List getPersonFromMessage(List checkedAllPerson, String searchText) { if (checkedAllPerson.size() != 0) { List 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 getValidBusinessRuleList() { List validBusinessRuleList = new ArrayList<>(); List 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; } // 根据人员id在有效的业务表中获取人员所在的业务表 public static List getPersonInValidBusinessList(String personId) { List personInValidBusinessList = new ArrayList<>(); List 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 getValidBusinessRuleListButTimeNotReach() { List validBusinessRuleButNotReachList = new ArrayList<>(); List 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; } // 根据人员ID,获取到人的未到时间的业务表 public static List getValidBusinessRuleListButTimeNotReach(String personId) { List personInValidBusinessRuleButNotReachList = new ArrayList<>(); List 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 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 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 "业务表:时间未到"; } }