高章伟
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
83
84
85
86
87
88
89
90
/**2021-08-31  mzy 
设备多时,FSE分批点检如果有遗漏设备的提醒设置
*/
public with sharing class InspectionRemindController {
    public String taId{get;set;} //点检计划Id
    //public List<String> BodyId {get;set;} //存放保有设备的Id
    //public Map<String,AssetInfo> BodyMap {get;set;} //存放保有设备信息
    public List<AssetInfo> BodyList {get;set;}
    public String getInit() {
 
        system.debug('记录Id :' +taId);
 
        if(String.IsBlank(taId)){
            //return 'Id不能为空';
            return '';
        }
        //初始化变量
        //BodyId = new List<String>();
        BodyList = new  List<AssetInfo>();
        /*
        //根据点检计划Id查询点检报告书
        List<Inspection_Report__c> InspectionReportList = [SELECT Id FROM Inspection_Report__c WHERE Inspectup_Plan__c = :taId];
        //根据点检报告书Id查询点检明细
        Set<String> IdSet = new Set<String>();
        if(InspectionReportList.size()>0){
            for(Inspection_Report__c It:InspectionReportList){
                IdSet.add(It.Id);
            }
            if(IdSet.size()>0){
                //查询点检明细
                List<Inspection_Item__c> InspectionItemList = [ SELECT Id,AssetId__c,AssetId__r.Id,AssetId__r.Name,AssetId__r.SerialNumber FROM Inspection_Item__c WHERE Inspection_ReportId__c = :IdSet];
 
                //构建Body
                if(InspectionItemList.size()>0){
                    for(Inspection_Item__c iitem:InspectionItemList){
                        if(!BodyId.contains(iitem.AssetId__c)){
                            BodyId.add(iitem.AssetId__c);
                            //BodyList.add(new AssetInfo(iitem.AssetId__c,iitem.AssetId__r.Name));
                            BodyList.add(new AssetInfo(iitem));
                        }
                    }
                }
            }
        }
        */  
 
 
           
            Map<String,String> AssetMap = new Map<String,String>();
            List<Inspection_Item__c> InspectionItemList = [select Id,name,AssetId__c,AssetId__r.Product_Serial_No__c,Inspection_ReportId__c,
            Inspection_ReportId__r.Inspectup_Plan__c from Inspection_Item__c where Inspection_ReportId__r.Inspectup_Plan__c = :taId and AssetId__c != null];
            if(InspectionItemList.size()>0){
                for(Inspection_Item__c iitem:InspectionItemList){
                    String ProductSerialNo = iitem.AssetId__r.Product_Serial_No__c;
                       AssetMap.put(ProductSerialNo,ProductSerialNo); 
                }
            }
 
            String ContractId = '';
            Inspectup_Plan__c ir0 = [SELECT Id,Maintenance_Contract__c FROM Inspectup_Plan__c WHERE id = :taId];
            ContractId = ir0.Maintenance_Contract__c;
 
            List<Maintenance_Contract_Asset__c>  mCAList = [Select Asset__c,Asset__r.Product_Serial_No__c,Asset__r.Product2.Asset_Model_No__c from Maintenance_Contract_Asset__c where Maintenance_Contract__c = :ContractId];
            if(mCAList.size()>0){
                for(Maintenance_Contract_Asset__c mca:mCAList){
                    String ProductSerialNo = mca.Asset__r.Product_Serial_No__c;
                    if(!AssetMap.containsKey(ProductSerialNo)){
                        BodyList.add(new AssetInfo(mca));
                    }
 
                }
            }
 
 
 
        return '';
 
    }
 
    class AssetInfo {
        public String ProductSerialNo { get; set; }
        public String AssetModelNo { get; set; }
 
        public AssetInfo(Maintenance_Contract_Asset__c mca){
            ProductSerialNo = mca.Asset__r.Product_Serial_No__c;
            AssetModelNo = mca.Asset__r.Product2.Asset_Model_No__c;
        }
    }
 
}