高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
global without sharing class AssetWebService {
 
    private static Set<String> assStatus = new Set<String>{'不明','废弃','未使用', '廃棄'};
 
    WebService static String createLostReport(String assetId) {
        return createLostReportCheck(assetId, true);
    }
 
    public static String createLostReportCheck(String assetId, Boolean isWeb) {
        try {
            List<Asset> asList = [SELECT Id
                                       , Account.Management_Code__c
                                       , Status
                                       , Asset_loaner_category__c
                                       , Internal_Asset_number_key__c
                                    FROM Asset
                                   WHERE id = :assetId];
            if (asList.size() == 0) {
                return '2:保有设备不存在,请刷新画面重试';
            }
            else {
                Asset ass = asList[0];
                if (ass.Account.Management_Code__c != System.Label.Account_Asset_FJZ) {
                    return '2:集中管理备品无法通过此路径创建遗失报告';
                }
                else if (String.isBlank(ass.Internal_Asset_number_key__c)) {
                    return '2:此保有设备不是固定资产,无法创建遗失报告';
                } else if (assStatus.contains(ass.Status)) {
                    return '2:此保有设备的状态不符合创建遗失报告的条件,无法创建遗失报告';
                }
            }
            List<LostReport__c> lrList = [SELECT Id, Name
                                            FROM LostReport__c
                                           WHERE Asset__c = :assetId
                                             AND Status__c != '取消提交'];
            if (lrList.size() > 0) {
                List<LostReport_Detail__c> ldList = [SELECT Id
                                                       FROM LostReport_Detail__c
                                                      WHERE LostReport__c = :lrList[0].Id
                                                        AND Asset__c = :assetId
                                                        AND CancelLostReport__c = false];
                if (ldList.size() > 0) {
                    return '2:已经创建遗失报告明细无需再次创建';
                }
            }
            return '1:' + assetId;
        }
        catch(Exception e) {
            return '2:' + e.getMessage();
        }
    }
 
    /**
     * 转换办事处到省
     * @param str 存放地
     * @return OCSM管理省名字
     */
    WebService static String getOcmMgtProvStr(String str) {
        Map<String, String> ocmMgtProvMap = AssetWebService.getOcmMgtProvMap();
        String res = '';
        System.debug(ocmMgtProvMap);
        System.debug(str);
        if (ocmMgtProvMap.containsKey(str)) {
            res = ocmMgtProvMap.get(str);
        }
        return res;
    }
 
    /**
     * 从 Label.OCM_Management_Province_Mapping
     * 取出 存放地 → 省 的 Map
     */
    public static Map<String, String> getOcmMgtProvMap() {
        Map<String, String> ocm_Map = new Map<String, String>();
        String OCM_Management_Province_Mapping = System.Label.OCM_Management_Province_Mapping;
        for (String str : OCM_Management_Province_Mapping.split(',')) {
            List<String> strList = str.split(':');
            ocm_Map.put(strList[1].trim(), strList[0].trim());
        }
        return ocm_Map;
    }
}