高章伟
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
public with sharing class ConsumUploadPictureController {
    public Boolean done_flag {get;set;}
    public Boolean hasPicture {get;set;}
    public String line {get;set;}
    public Consum_Apply_Equipment_Set_Detail__c caesd {get;set;}
    public ConsumUploadPictureController() {}
    public void init() {
        String caesd_id = System.currentPageReference().getParameters().get('caesd_id');
        line = System.currentPageReference().getParameters().get('line');
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [
                SELECT Picture1__c
                     , Picture2__c
                     , Consum_Apply__r.Id
                     , Received_Confirm__c
                     , Fixture_Model_No_F__c
                     , ProductName__c
                     , Degree_Of_Importance__c
                     , RAESD_Status__c
                     , Consumable_Guaranteen_end_F__c
                     , Consum_Apply__r.HP_received_sign_rich__c
                     , Follower_User__c
                  FROM Consum_Apply_Equipment_Set_Detail__c
                 WHERE Id = : caesd_id
            ];
        if (caesdList.size() > 0) {
            caesd = caesdList[0];
        }
        else {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR, '无效的耗材明细Id');
            ApexPages.addMessage(errorMessage);
        }
    }
    public PageReference save() {
        Savepoint sp = Database.setSavepoint();
        try{
            List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [
                    SELECT Picture1__c
                         , Picture2__c
                         , Received_Confirm__c
                         , Fixture_Model_No_F__c
                         , ProductName__c
                         , Degree_Of_Importance__c
                         , RAESD_Status__c
                         , Consumable_Guaranteen_end_F__c
                         , Consum_Apply__r.HP_received_sign_rich__c
                         , Follower_User__c
                      FROM Consum_Apply_Equipment_Set_Detail__c
                     WHERE Id = : caesd.Id
                       FOR UPDATE
                ];
            if (caesdList.size() == 1) {
                Consum_Apply_Equipment_Set_Detail__c newCaesd = caesdList[0];
                if(newCaesd.RAESD_Status__c == Consum_ApplyUtil.CaStatusMap.get(Consum_ApplyUtil.CaesdStatus.Yi_Xiao_Hao.ordinal())) {
                    throw new ControllerUtil.myException('耗材明细已消耗,不可以更新图片,Id=' + caesd.Id);
                }
                if (String.isNotBlank(newCaesd.Consum_Apply__r.HP_received_sign_rich__c)) {
                    throw new ControllerUtil.myException('耗材申请已上传试用表,不可以更新' );
                }
                newCaesd.Picture1__c = caesd.Picture1__c;
                newCaesd.Picture2__c = caesd.Picture2__c;
                FixtureUtil.withoutUpdate(new List<Consum_Apply_Equipment_Set_Detail__c> {newCaesd});
                done_flag = true;
                hasPicture = String.isNotBlank(newCaesd.Picture1__c)||String.isNotBlank(newCaesd.Picture2__c);
                return null;
            }
            else {
                throw new ControllerUtil.myException('耗材明细不存在,可能已被删除,Id=' + caesd.Id);
            }
        }
        catch (Exception e) {
            Database.rollback(sp);
            ApexPages.addMessages(e);
            done_flag = false;
            return null;
        }
    }
    public PageReference goback(){
        PageReference pageRef = new PageReference('/apex/ConsumTrialUpdate?parid=' + caesd.Consum_Apply__r.Id);
        return pageRef;
    }
}