高章伟
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
public without sharing class ProductRepairQuoteController {
    public String productId { get; set; }
    public String flag { get; set; }
    public String msg { get; private set; }
    public String pId { get; set; }
    public Boolean viewFlag { get; set; }
    public Product2 product { get; private set; }
    public String repairListPriceLevelA { get { return product == null ? '' : String.valueOf(product.RepairListPriceLevelA__c); } }
    public String repairListPriceLevelB { get { return product == null ? '' : String.valueOf(product.RepairListPriceLevelB__c); } }
    public String repairListPriceLevelC { get { return product == null ? '' : String.valueOf(product.RepairListPriceLevelC__c); } }
    public Date partSupplyFinishDate { get { return product.PartSupplyFinishDate__c; } }
 
    public ProductRepairQuoteController() {
        productId = ApexPages.currentPage().getParameters().get('productid');
        flag = ApexPages.currentPage().getParameters().get('flag');
    }
 
    public void init(){
        viewFlag = true;
        msg = '以下仅为参考报价,最终修理价格以报价单为准';
        String usrProfileName = [select u.Profile.Name from User u where u.id = :Userinfo.getUserId()].Profile.Name;
        //asset    repair(传进来保有设备Id)       product
        List<Asset> assetList = new List<Asset>();
        List<Product2> productList = new List<Product2>();
        Map<String,String> adminProfileMap = new Map<String,String>();
        Map<String,String> notadminProfileMap = new Map<String,String>();
        List<String> adminProfileList = System.Label.profileName_adminand2F1.split(',');
        for(Integer i = 0; i < adminProfileList.size(); i++){
            adminProfileMap.put(adminProfileList[i], adminProfileList[i]);
        }
        List<String> notadminProfileList = System.Label.profileName_Notadminand2F1.split(',');
        for(Integer i = 0; i < notadminProfileList.size(); i++){
            notadminProfileMap.put(notadminProfileList[i], notadminProfileList[i]);
        }
        if(flag == 'asset'){
            if(notadminProfileMap.containsKey(usrProfileName)){
                assetList = [select Id,Product2Id,Product2.RepairListPriceLevelA__c,
                                    Product2.RepairListPriceLevelB__c  
                                    from Asset 
                                    where Id = :productId];
                if(assetList.size() > 0){
                    pId = assetList[0].Product2Id;
                }else{
                    viewFlag = false;
                    msg = '';
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '产品不存在,请确认。'));
                }
            }else{
                viewFlag = false;
                msg = '您没有足够的权限执行所请求的操作。如果需要访问,请联系记录所有人或管理员。';
            }
        }
        if(flag == 'product'){
            if(adminProfileMap.containsKey(usrProfileName)){
                pId = productId;
            }else{
                viewFlag = false;
                msg = '您没有足够的权限执行所请求的操作。如果需要访问,请联系记录所有人或管理员。';
            }
        }
        if(flag == 'productsearch'){
            if(notadminProfileMap.containsKey(usrProfileName)){
                List<Product2__c> product2List = [select Id,Product2__c
                                    from Product2__c
                                    where Id = :productId];
                if(product2List.size() > 0){
                    pId = product2List[0].Product2__c;
                }else{
                    viewFlag = false;
                    msg = '';
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '产品不存在,请确认。'));
                }
            }else{
                viewFlag = false;
                msg = '您没有足够的权限执行所请求的操作。如果需要访问,请联系记录所有人或管理员。';
            }
        }
        if(viewFlag){
            productList = [select Id,Name,RepairListPriceLevelA__c,
                                RepairListPriceLevelB__c,RepairListPriceLevelC__c,
                                PartSupplyFinishDate__c
                                from Product2
                                where Id = :pId];
            if(productList.size() >0){
                product = productList[0];
            }else{
                viewFlag = false;
                msg = '';
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '产品不存在,请确认。'));
            }
        }
    }
}