高章伟
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
public with sharing class QuestionnaireAllowanceController {
    //用户信息
    public user userdet { get; set; }
    public Questionnaire_Survey__c csc { get; set; }
    public Boolean btn {get;set;}
    // 问卷 ID
    public String qsId  { get; set; }
    public QuestionnaireAllowanceController() {
        qsId = ApexPages.currentPage().getParameters().get('qsId');
        btn = false;
    }
    // 画面初始化
    public void init() {
        userdet = [SELECT Work_Location__c,Job_Category__c,Post__c FROM user where id = :UserInfo.getUserId()];
        csc = new Questionnaire_Survey__c();
        if(String.isNotBlank(qsId)){
            csc = [SELECT Id, Accept_GPS__c, Accept_traffic_Text__c, Accept_traffic__c, AutoNumber__c,
                        Incharge_Hospital_Count__c, Incharge_Hospital_FarthestDistance__c, Incharge_Hospital_Location__c,
                        Incharge_Hospital_NearestDistance__c, Most_dissatisfied__c, Most_satisfied__c,Notaccept_GPS_Reason__c,
                        Other_Visitefficiency_Text__c, Other_Visitefficiency__c,Questionnaire_user__c, TeamWork_efficiency_Text__c,
                        Traffic_subsidy_Opinion__c, Traffic_subsidy_Status__c, Traffic_subsidy_balance__c, Trip_Mode_Other__c,
                        Trip_Mode__c, User_Job_Category__c, User_Post__c, User_Work_Location__c, Visit_efficiency_quality_Text__c,
                        Visit_efficiency_quality__c, Workeffectiveness_departments_Text__c, Workeffectiveness_departments__c,
                        TeamWork_efficiency__c, Traffic_expense_reason__c,Questionnaire_Status__c
                        FROM Questionnaire_Survey__c WHERE Id = :qsId];
        }
    }
    // 保存按钮
    public PageReference save() {
        Questionnaire_Survey__c qs = new Questionnaire_Survey__c();
        //一、工作情况调查
        if(String.isBlank(csc.Incharge_Hospital_Count__c)){
            csc.Incharge_Hospital_Count__c.addError('请选择负责目标医院数量。');
            return null;
        }
        if(String.isBlank(csc.Incharge_Hospital_Location__c)){
            csc.Incharge_Hospital_Location__c.addError('请选择目标医院位置。');
            return null;
        }
        if(csc.Incharge_Hospital_FarthestDistance__c <= 0 || String.isBlank(String.valueOf(csc.Incharge_Hospital_FarthestDistance__c))){
            csc.Incharge_Hospital_FarthestDistance__c.addError('请录入最远距离。');
            return null;
        }
        if(csc.Incharge_Hospital_NearestDistance__c <= 0 || String.isBlank(String.valueOf(csc.Incharge_Hospital_NearestDistance__c))){
            csc.Incharge_Hospital_NearestDistance__c.addError('请录入最近距离。');
            return null;
        }
        if(csc.Incharge_Hospital_NearestDistance__c > csc.Incharge_Hospital_FarthestDistance__c){
            csc.Incharge_Hospital_FarthestDistance__c.addError('最远距离小于最近距离。');
            return null;
        }
        if(String.isBlank(csc.Trip_Mode__c)){
            csc.Trip_Mode__c.addError('请选择出行方式。');
            return null;
        }
        if(String.valueOf(csc.Trip_Mode__c) == '④其他' && String.isBlank(csc.Trip_Mode_Other__c)){
            csc.Trip_Mode_Other__c.addError('请录入具体出行方式。');
            return null;
        }
        //二、工作效率调查
        if(String.isBlank(csc.Visit_efficiency_quality__c)){
            csc.Visit_efficiency_quality__c.addError('请选择拜访效率/质量。');
            return null;
        }
        if(String.isBlank(csc.Visit_efficiency_quality_Text__c)){
            csc.Visit_efficiency_quality_Text__c.addError('请列举具体数据或事例');
            return null;
        }
        if(String.isBlank(csc.Other_Visitefficiency__c)){
            csc.Other_Visitefficiency__c.addError('请选择他方面的工作效率。');
            return null;
        }
        if(String.isBlank(csc.Other_Visitefficiency_Text__c)){
            csc.Other_Visitefficiency_Text__c.addError('请列举具体数据或事例');
            return null;
        }
        if(String.isBlank(csc.TeamWork_efficiency__c)){
            csc.TeamWork_efficiency__c.addError('请选择团队成员工作效率。');
            return null;
        }
        if(String.isBlank(csc.TeamWork_efficiency_Text__c)){
            csc.TeamWork_efficiency_Text__c.addError('请列举具体数据或事例');
            return null;
        }
        if(String.isBlank(csc.Workeffectiveness_departments__c)){
            csc.Workeffectiveness_departments__c.addError('请选合作部门工作效率。');
            return null;
        }
        if(String.isBlank(csc.Workeffectiveness_departments_Text__c)){
            csc.Workeffectiveness_departments_Text__c.addError('请列举具体数据或事例');
            return null;
        }
        //三、满意度情况调查
//        if(String.isBlank(csc.Traffic_subsidy_Status__c)){
//            csc.Traffic_subsidy_Status__c.addError('请选择实际支出。');
//            return null;
//        }
//        if(String.valueOf(csc.Traffic_subsidy_Status__c) == '③不能满足' && (String.isBlank(String.valueOf(csc.Traffic_subsidy_balance__c)) || csc.Traffic_subsidy_balance__c <= 0)){
//            csc.Traffic_subsidy_balance__c.addError('请录入差额');
//            return null;
//        }
        if(String.isBlank(csc.Most_satisfied__c)){
            csc.Most_satisfied__c.addError('在试行市内交通补贴期间,您最满意的是什么');
            return null;
        }
        if(String.isBlank(csc.Most_dissatisfied__c)){
            csc.Most_dissatisfied__c.addError('在试行市内交通补贴期间,您最不满意的是什么');
            return null;
        }
        //四、意见和建议
        if(String.isBlank(csc.Accept_traffic__c)){
            csc.Accept_traffic__c.addError('请选择愿意接受的交通费用政策');
            return null;
        }
        if(csc.Accept_traffic__c == '③其他(请说明)' && String.isBlank(csc.Accept_traffic_Text__c)){
            csc.Accept_traffic_Text__c.addError('请列举具体数据或事例');
            return null;
        }
        if(String.isBlank(csc.Traffic_expense_reason__c)){
            csc.Traffic_expense_reason__c.addError('请说明选择以上方式的原因');
            return null;
        }
        if(String.isBlank(csc.Accept_GPS__c)){
            csc.Accept_GPS__c.addError('请选择是否接受GPS');
            return null;
        }
        if(csc.Accept_GPS__c == '②不能接受' && String.isBlank(csc.Notaccept_GPS_Reason__c)){
            csc.Notaccept_GPS_Reason__c.addError('请说明不接受GPS原因');
            return null;
        }
        if(String.isBlank(csc.Traffic_subsidy_Opinion__c)){
            csc.Traffic_subsidy_Opinion__c.addError('请提出你的意见或建议');
            return null;
        }
        if(String.isNotBlank(qsId)){
            qs.id = qsId;
        }else{
            qs.Name = '*';
        }
        qs.Questionnaire_user__c = UserInfo.getUserId();
        qs.Incharge_Hospital_Count__c = csc.Incharge_Hospital_Count__c;
        qs.Incharge_Hospital_Location__c = csc.Incharge_Hospital_Location__c;
        qs.Incharge_Hospital_FarthestDistance__c = csc.Incharge_Hospital_FarthestDistance__c;
        qs.Incharge_Hospital_NearestDistance__c = csc.Incharge_Hospital_NearestDistance__c;
        qs.Trip_Mode__c = csc.Trip_Mode__c;
        qs.Trip_Mode_Other__c = csc.Trip_Mode_Other__c;
        //二、工作效率调查
        qs.Visit_efficiency_quality__c = csc.Visit_efficiency_quality__c;
        qs.Visit_efficiency_quality_Text__c = csc.Visit_efficiency_quality_Text__c;
        qs.Other_Visitefficiency__c = csc.Other_Visitefficiency__c;
        qs.Other_Visitefficiency_Text__c = csc.Other_Visitefficiency_Text__c;
        qs.TeamWork_efficiency__c = csc.TeamWork_efficiency__c;
        qs.TeamWork_efficiency_Text__c = csc.TeamWork_efficiency_Text__c;
        qs.Workeffectiveness_departments__c = csc.Workeffectiveness_departments__c;
        qs.Workeffectiveness_departments_Text__c = csc.Workeffectiveness_departments_Text__c;
        //三、满意度情况调查
        qs.Traffic_subsidy_Status__c = csc.Traffic_subsidy_Status__c;
        qs.Traffic_subsidy_balance__c = csc.Traffic_subsidy_balance__c;
        qs.Most_satisfied__c = csc.Most_satisfied__c;
        qs.Most_dissatisfied__c = csc.Most_dissatisfied__c;
        //三、满意度情况调查
        qs.Accept_traffic__c = csc.Accept_traffic__c;
        qs.Accept_traffic_Text__c = csc.Accept_traffic_Text__c;
        qs.Traffic_expense_reason__c = csc.Traffic_expense_reason__c;
        qs.Accept_GPS__c = csc.Accept_GPS__c;
        qs.Notaccept_GPS_Reason__c = csc.Notaccept_GPS_Reason__c;
        qs.Traffic_subsidy_Opinion__c = csc.Traffic_subsidy_Opinion__c;
        Savepoint sp = Database.setSavepoint();
        try{
            upsert qs;
            btn = true;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '保存成功'));
        } catch (Exception e) {
            ApexPages.addMessages(e);
            Database.rollback(sp);
        }
        qsId = qs.Id;
        return UnabletoEdit();
    }
    // 返回不可编辑状态
    public PageReference UnabletoEdit(){
        PageReference ref = new Pagereference('/apex/QuestionnaireAllowance?qsId='+qsId);
        ref.setRedirect(true);
        return ref;
    }
    // 提交按钮
    public PageReference Sorder() {
        Savepoint sp = Database.setSavepoint();
        try {
            Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
            psr.setObjectId(qsId);
            Approval.ProcessResult submitResult = Approval.process(psr);
            init();
            return  null;
        }
        catch (Exception e) {
            ApexPages.addmessages(e);
            Database.rollback(sp);
            return  null;
        }
    }
 
}