a
554325746@qq.com
2019-12-24 570a73851c26d810c2597596a8acc8a8d4cde211
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
package com.basic.security.manager;
 
import android.text.TextUtils;
 
import com.basic.security.model.Identity;
import com.basic.security.model.ModelAdapter;
import com.basic.security.model.PersonIdentity;
import com.basic.security.utils.Constants;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
 
public class IdentityManager extends BaseManager {
    public static List<ModelAdapter> findIdentityList() {
        return findList("select * from identity ");
//        return findIdentityList1();
    }
 
    public static List<ModelAdapter> findIdentityList1() {
        List<ModelAdapter> allIdentityList = findList("select * from identity where " + Identity.name + "!='访客'");
        List<ModelAdapter> allIdentityList2 = findList("select * from identity where " + Identity.name + "='访客'");
        if (allIdentityList2.size() > 0) {
            allIdentityList.add(0, allIdentityList2.get(0));
        }
        return allIdentityList;
    }
 
    public static List<String> findIdentityNameListByPersonId(String personId) {
        List<String> identityNameList = new ArrayList();
        List<ModelAdapter> personPersonIdentity = PersonIdentityManager.findPersonIdentityListByPersonId(personId);
        for (ModelAdapter personIdentity : personPersonIdentity) {
            String identityId = personIdentity.getString("identity_id");
            ModelAdapter identityDocument = findById("identity", identityId);
            if (identityDocument != null) {
                String identityName = identityDocument.getString("name");
                if (!TextUtils.isEmpty(identityName)) {
                    identityNameList.add(identityName);
                }
            }
        }
        return identityNameList;
    }
 
    public static ModelAdapter findIdentityById(String id) {
        return BaseManager.findById("identity", id);
    }
 
    public static ModelAdapter findIdentityByName(String identityName) {
        ModelAdapter identity = findOne("select * from " + Identity.tableName + " where " + Identity.name + "='" + identityName + "'");
        if (identity == null) {
            identity = new ModelAdapter();
            identity.setString(Identity.id, UUID.randomUUID().toString());
            identity.setString(Identity.name, identityName);
            identity.setString(Identity.del_flag, "0");
            identity.setString(Constants.TABLE, Identity.tableName);
            identity.setString(Identity.device_id, DeviceManager.getDeviceId());
            save(identity);
        }
        return identity;
    }
 
    public static String findIdentityNamesByPersonId(String personId) {
        List<ModelAdapter> identityList = findList("select b.* from " + PersonIdentity.tableName + " a left join "
                + Identity.tableName + " b on a." + PersonIdentity.identity_id + "=b." + Identity.id +
                " where a." + PersonIdentity.person_id + "='" + personId + "' "
        );
        List<String> names = new ArrayList<>();
        for (ModelAdapter identity : identityList) {
            names.add(identity.getString(Identity.name));
        }
        return TextUtils.join(",", names);
    }
 
    public static Map<String, ModelAdapter> findAllIdentitiesMap() {
        List<ModelAdapter> identityList = findList("select * from " + Identity.tableName);
        Map<String, ModelAdapter> identityMap = new HashMap<>();
        for (ModelAdapter identity : identityList) {
            identityMap.put(identity.getString(Identity.name), identity);
        }
        return identityMap;
    }
}