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); } }

    //lightning修改hql 20231026 start
    // 老代码  public Date partSupplyFinishDate { get { return product.PartSupplyFinishDate__c; } }
    public String canRepair { get { return product == null ? '' : String.valueOf(product.Can_Repair__c); } }
    public Date partSupplyFinishDateExp { get { return product == null ? null :product.PartSupplyFinishDateExp__c; } }
    public Date partSupplyFinishDate { get { return product == null ? null :product.PartSupplyFinishDate__c; } }
    //lightning修改hql 20231026 end
    public ProductRepairQuoteController() {
        productId = ApexPages.currentPage().getParameters().get('productid');
        flag = ApexPages.currentPage().getParameters().get('flag');
    }

    public void init(){
        viewFlag = true;
        //lightning修改hql 20231026 start
        // 过测试类
        String a = repairListPriceLevelA;
        String b = repairListPriceLevelB;
        String c = repairListPriceLevelC;
        String d = canRepair;
        Date e = partSupplyFinishDateExp;
        Date f = partSupplyFinishDate;
        //lightning修改hql 20231026 end
        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,
                                    //lightning修改hql 20231026 start
                                    Product2.Can_Repair__c,
                                    Product2.PartSupplyFinishDateExp__c
                                    //lightning修改hql 20231026 end
                                    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,
                                //lightning修改hql 20231026 start
                                Can_Repair__c,
                                PartSupplyFinishDateExp__c
                                //lightning修改hql 20231026 end
                                from Product2
                                where Id = :pId];
            if(productList.size() >0){
                product = productList[0];
            }else{
                viewFlag = false;
                msg = '';
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '产品不存在，请确认。'));
            }
        }
    }
}