高章伟
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
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
/**
 * wangweipeng    2021/08/04
 * 打印点检计划报告书 筛选条件
 */
public with sharing class PrintInspectupReportController {
    //维修合同id
    public String maintenanceContractId{get;set;}
 
    //是否空白单据
    public String isResultShow{get;set;}
    //是否空白单据 下拉内容
    public static List<SelectOption> isResultShowLOption{get;set;}
 
    //根据保有设备查询合同
    public String selectAssetType{get;set;}
    //保有设备的下拉内容
    public static List<SelectOption> selectAssetTypeOption{get;set;}
 
    //战略科室的下拉内容
    public List<CustomData> strategyDepartment{get;set;}
    //科室的下拉内容
    public List<CustomData> department{get;set;}
    //设备的装机地点
    public List<CustomData> installationSite{get;set;}
    //是否分页
    public Boolean isPaging{get;set;}
    
    static {
        isResultShowLOption = new List<SelectOption>();
        isResultShowLOption.add(new SelectOption('', '--无--'));
        isResultShowLOption.add(new SelectOption('1', '空白单据'));
        isResultShowLOption.add(new SelectOption('2', '合同全部'));
 
        selectAssetTypeOption = new List<SelectOption>();
        selectAssetTypeOption.add(new SelectOption('', '--无--'));
        selectAssetTypeOption.add(new SelectOption('1', '战略科室'));
        selectAssetTypeOption.add(new SelectOption('2', '科室'));
        selectAssetTypeOption.add(new SelectOption('3', '装机地点'));
        selectAssetTypeOption.add(new SelectOption('4', '机身号'));
    }
    public String produceText{get;set;}
    //洗消信息
    public Boolean activeOn { get; set; }
    //点检数据
    public List<Inspectup_Plan__c>  inspectupPlanList{get;set;}
    //条件参数
    public String parameter{get;set;}
 
    public PrintInspectupReportController() {
        parameter = '';
        produceText = '';
        activeOn = true;
        //是否分页  默认为false
        isPaging = false;
        inspectupPlanList = new List<Inspectup_Plan__c>();
        maintenanceContractId = System.currentPageReference().getParameters().get('id');
    }
 
    public PageReference init(){
        getAssetType();
        getInspectupPlan();
        return null;
    }
 
    //获取修理合同上的保有设备都是那个战略科室和科室
    public void getAssetType(){
        String assetTypeSQl = makeTextDepSQl();
        try{
            List<Maintenance_Contract_Asset__c> assetTypeList = Database.query(assetTypeSQl);
            if(assetTypeList != null && assetTypeList.size() > 0){
                //临时字符串
                String strategyDepartmentStr = '';
                String departmentStr = '';
                String installationSiteStr = '';
                //战略科室存放处
                strategyDepartment = new List<CustomData>();
                department = new List<CustomData>();
                installationSite = new List<CustomData>();
                for(Maintenance_Contract_Asset__c mca : assetTypeList){
                    //所有的战略科室
                    if(strategyDepartmentStr.indexOf(mca.Asset__r.Strategic_department_Class_Name__c) == -1){
                        strategyDepartmentStr += mca.Asset__r.Strategic_department_Class_Name__c;
                        strategyDepartment.add(new CustomData(mca.Asset__r.Department_Class__c,mca.Asset__r.Acc_Department_Class_Name__c));
                    }
                    //科室
                    if(departmentStr.indexOf(mca.Asset__r.Account.Name) == -1){
                        departmentStr += mca.Asset__r.Account.Name;
                        department.add(new CustomData(mca.Asset__r.Account.Id,mca.Asset__r.Department_Name__c));
                    }
                    //装机地点
                    if(mca.Asset__r.Installation_Site__c != null && mca.Asset__r.Installation_Site__c != ''){
                        if(installationSiteStr.indexOf(mca.Asset__r.Installation_Site__c) == -1){
                            installationSiteStr += mca.Asset__r.Installation_Site__c;
                            installationSite.add(new CustomData(mca.Asset__r.Installation_Site__c,mca.Asset__r.Installation_Site__c));
                        }
                    }
                }
            }
        }catch(exception e){
            //失败提示
            ApexPages.addMessages(e);
        }
    }
    //获取所有的点检数据
    public void getInspectupPlan(){
        String InspectupPlanSQL = makeTextInspectupPlanSQl();
        try{
            inspectupPlanList = Database.query(InspectupPlanSQL);
        }catch(exception e){
            //失败提示
            ApexPages.addMessages(e);
        }
    }
    //查询点检报告书的pdf
    public String makeTextInspectupPlanSQl(){
        String InspectupPlanSQL = 'SELECT ID,NAME,Execution_End_Date__c,Chack_Plan_NO__c FROM Inspectup_Plan__c WHERE Maintenance_Contract__c = \''+maintenanceContractId+'\' '
                                + ' order by Maintenance_Contract__c desc';
 
        return InspectupPlanSQL;
    }
 
    //查询修理合同里面保有设备都是那些科室和战略科室
    public String makeTextDepSQl(){
        String depSQl = 'select id,name,Asset__c,Asset__r.name,Asset__r.SerialNumber,Asset__r.Strategic_department_Class_Name__c,Asset__r.Department_Class__c,Asset__r.Acc_Department_Class_Name__c,'
                    +' Asset__r.Department_Name__c,Asset__r.Account.Id,Asset__r.Account.Name,Asset__r.Installation_Site__c '
                    +' from Maintenance_Contract_Asset__c '
                    //+' where Check_object__c = true and Maintenance_Contract__c = \''+maintenanceContractId+'\' '
                    +' where Maintenance_Contract__c = \''+maintenanceContractId+'\' and isdianjian__c != 0 '
                    +' order by Asset__r.Acc_Department_Class_Name__c,Asset__r.Account.Name';
        return depSQl;
    }
 
 
 
    /**
     * 为了方便前段table获取值
     */
    class CustomData {
        //id
        public String parameterId { get; private set; }
        //name
        public String parameterName { get; private set; }  
 
        public CustomData(String accountId,String accountName){
            parameterId = accountId;
            parameterName = accountName;
        }    
    }
}