public class ReceivingNoteController {
    //查询备品收货清单一览  父集   Id
    @AuraEnabled
    public static string methodName(){
        QueryWrapper query = new QueryWrapper(ReceivingNote__c.SObjectType);
        // List<ReceivingNote__c> arrays = DataBasePlus.listPlus(query);
        String sql = 'select ';
        String props = CommonUtils.GetSqlToPorps(ReceivingNote__c.SObjectType);
        String guding = '固定资产';
        String beipin1 = '北京 备品中心';
        String beipin2 = '上海 备品中心';
        String beipin3 = '广州 备品中心';
        sql += props+' from ReceivingNote__c where Asset_loaner_category__c=:guding AND Internal_asset_location__c!=:beipin1 AND Internal_asset_location__c!=:beipin2 AND Internal_asset_location__c!=:beipin3';
        List<ReceivingNote__c> arrays= Database.query(sql);

        return JSON.serialize(arrays);
    }

    //查询备品收货清单一览明细  子集  ReceivingNote__c
    @AuraEnabled
    public static string beiPing(String rndId){
        String sql = 'select ';
        String props = CommonUtils.GetSqlToPorps(ReceivingNoteDetail__c.SObjectType);
        sql += props+' from ReceivingNoteDetail__c where ReceivingNote__c = :rndId';
        List<ReceivingNoteDetail__c> results = Database.query(sql);

        return JSON.serialize(results);
    }

    //查询保有设备详细信息
    @AuraEnabled
    public static string baoYouSheBei(String aAssert){
        String sql = 'select ';
        String props = CommonUtils.GetSqlToPorps(asset.SObjectType);
        sql += props+' from asset where Id = :aAssert';
        system.debug(sql);

        List<asset> results = Database.query(sql);
        return JSON.serialize(results);
        //return sql;
    }


    //检索方法   String BPLBValue, String LXRValue, String FHRValue, String HTBMValue, String DDBMVaule, String CGSQCJHValue
    @AuraEnabled
    public static string serachofCondition (String BPLBValue, String LXRValue, String FHRValue, String HTBMValue, String DDBMVaule, String CGSQCJHValue){
        // String props = CommonUtils.GetSqlToPorps(ReceivingNote__c.SObjectType);
        //QueryWrapper query = new QueryWrapper(ReceivingNote__c.SObjectType);
        // String wher = '';
        // if(BPLBValue != ''){
        //     query.eq('Asset_loaner_category__c',BPLBValue);
        //     //wher += ' AND Asset_loaner_category__c = :BPLBValue';
        // }
        // if(LXRValue != ''){
        //     query.eq('Field1_test__c',LXRValue);
        //     //wher += ' AND WHERE Field1_test__c = :LXRValue';
        // }
        // if(FHRValue != ''){
        //     // SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd');
        //     // Date date = sdf.parse(FHRValue);
        //     Date newDate = Date.valueOf(FHRValue);
        //     query.eq('DateOfDelivery__c',FHRValue);
        //     //wher += ' AND WHERE DateOfDelivery__c = :FHRValue';
        // }
        // if(HTBMValue != ''){
        //     query.eq('Sales_order_number__c',HTBMValue);
        //     //wher += ' AND WHERE Sales_order_number__c = :HTBMValue';
        // }
        // if(DDBMVaule != ''){
        //     query.eq('OrderCode__c',DDBMVaule);
        //     //wher += ' AND WHERE OrderCode__c = :DDBMVaule';
        // }
        // if(CGSQCJHValue != ''){
        //     query.eq('ApprovalNumber__c',CGSQCJHValue);
        //     //wher += ' AND WHERE ApprovalNumber__c = :CGSQCJHValue';
        // }
        // List<ReceivingNote__c> arrays= Database.query(sql);
        //List<ReceivingNote__c> arrays = DataBasePlus.listPlus(query);
        // DataBasePlus.Mysql  获取sql语句

        String sql = 'select ';
        String props = CommonUtils.GetSqlToPorps(ReceivingNote__c.SObjectType);
        sql += props+' from ReceivingNote__c where Asset_loaner_category__c like \'%' + BPLBValue +'%\'';
        if(LXRValue != ''){
            sql += ' AND ContactPerson__c like \'%' + LXRValue + '%\'';
        }
        if(FHRValue != ''){
            //Date newDate = Date.valueOf(FHRValue);
            sql += ' AND  DateOfDelivery__c = ' + FHRValue;
        }
        if(HTBMValue != ''){
            sql += ' AND  Sales_order_number__c like \'%' + HTBMValue + '%\'';
        }
        if(DDBMVaule != ''){
            sql += ' AND  OrderCode__c like \'%' + DDBMVaule + '%\'';
        }
        if(CGSQCJHValue != ''){
            sql += ' AND  ApprovalNumber__c like \'%' + CGSQCJHValue + '%\'';
        }
        
        List<ReceivingNote__c> result = Database.query(sql);
        //return sql;
        return JSON.serialize(result);
    }

    // List<LostData> LostDataList = (List<LostData>)JSON.deserialize(LostDataJSON,List<LostData>.class);
    
    // Database.update(LostDataList, false);

    //修改备品收货清单配套一览明细详细信息的数据
    @AuraEnabled
    public static String modfiyDetail(String JsonDate){
        List<ReceivingNoteDetail__c> receivingNoteList = (List<ReceivingNoteDetail__c>)JSON.deserialize(JsonDate,List<ReceivingNoteDetail__c>.class);
        try{
            Database.update(receivingNoteList,false);
            return 'success';
        }catch(Exception ex){
            return  ex.getMessage();
        }
    }

    //修改保有资产
    @AuraEnabled
    public static String modfiyBaoYouZiChan(String JsonDate){
        List<Asset> receivingNoteList = (List<Asset>)JSON.deserialize(JsonDate,List<Asset>.class);
        for(Asset item : receivingNoteList){
            //保有资产对象属性修改为指定值
            item.AccountId = System.Label.Olympus_FJZ;  //Olympus社内 其他 备品(非集中管理)
            item.AssetManageConfirm__c = false;
        }

        try{
            Database.update(receivingNoteList,false);
            return 'success';
        }catch(Exception err){
            return err.getMessage();
        }
        
    }

    public class Modal{
        List<Object> resultList;
        String count;
        public Modal(List<Object> resultList,String count){
            resultList = this.resultList;
            count = this.count;
        }
    }
}