高章伟
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
public class ConsumApplyCancelController {
 
    /*--------- private ---------*/
    private Id objId {get; set;}
 
    /*--------- public ---------*/
    public Consum_Apply__c ra {get; set;}
    public String saveStatus {get; set;}
 
 
    /**
    * @description ConsumApplyCancelController   Class的构造函数
    * @param objId 申请书ID
    **/
    public ConsumApplyCancelController() {
        this.objId = ApexPages.currentPage().getParameters().get('objId');
    }
 
    /**
    * @description ConsumApplyCancelController 初始化方法
    **/
    public void init() {
        try{
          if (String.isBlank(this.objId)) {
             throw new ControllerUtil.myException('请设置耗材借出申请的Id');
          }
          if (String.isNotBlank(this.objId)) {
              List<Consum_Apply__c> ras = getRas(this.objId);
              if (ras.size() == 0) {
                throw new ControllerUtil.myException('没有检索出耗材申请');
              }
              this.ra = ras[0];
          }
        }
        catch (Exception e) {
            System.debug(e.getStackTraceString());
            ApexPages.addMessages(e);
            return;
        }
    }
 
    /**
    * @description 保存取消状态
    **/
    public void saveCancel() {
        Savepoint sp = Database.setSavepoint();
        try {
            // SWAG-BFV6G4 start
            StaticParameter.rentalApplyIsRunning = true;
            // SWAG-BFV6G4 end
            if (String.isBlank(this.ra.Cancel_Reason__c)) {
                throw new ControllerUtil.myException('请输入取消理由');
            }
            if (String.isBlank(this.ra.Loaner_cancel_request__c)) {
                throw new ControllerUtil.myException('备品申请取消理由备注');
            }
            FixtureUtil.withoutUpdate(new Consum_Apply__c[]{this.ra});
            String statusMessage;
            statusMessage = ConsumApplyWebService.ConsumApplyCancel(objId, false);
            if (statusMessage != '1') {
                throw new ControllerUtil.myException(statusMessage);
            }
            saveStatus = 'ok';
        }
        catch (Exception e) {
            Database.rollback(sp);
            System.debug(e.getStackTraceString());
            ApexPages.addMessages(e);
            saveStatus = 'ng';
            return;
        }
    }
 
    /**
    * @description 备品借出申请取得
    **/
    private List<Consum_Apply__c> getRas(Id raId) {
       return [SELECT Id
                    , Name
                    , OwnerId
                    , Status__c
                    , RA_Status__c
                    , Cancel_Reason__c
                    , Loaner_cancel_request__c
                    //, StockDown_ng_num__c
                    , Consum_Apply_Equipment_Set_Detail_Cnt__c
                 FROM Consum_Apply__c
                WHERE Id = :raId];
    }
}