binxie
2023-06-26 00e147ec892cb1e89d0698787a8c60da1014cdb7
force-app/main/default/classes/LexConsumableController.cls
@@ -105,6 +105,8 @@
    // 登录者工作地
    private static String userWorkLocation;
    public static String agencyProType { get; set; }
    public static String agencyProType1 { get; set; } //lt 20230526 安徽两票制 add
    private static Boolean OSHFLG; //lt 20230517 安徽两票制 add
    public static String methodType { get; set; }
    public static String hospitalName { get; set; }
    public static String hospitalId { get; set; }
@@ -165,9 +167,11 @@
            if (selectedIdMap.containsKey(consumableorderdetailsRecords[i].Prod.Id)) {
                addNo++;
                //continue;
            } else if (consumableorderdetailsRecordsview.size() >= pageLimit + size) {
                break;
            } else {
            }
            // else if (consumableorderdetailsRecordsview.size() >= pageLimit + size) {
            //     break;
            // }
            else {
                if (consumableorderdetailsRecords[i].check == false) {
                    consumableorderdetailsRecords[i].esd = orderdetails1;
                }
@@ -175,8 +179,8 @@
                consumableorderdetailsRecordsview.add(consumableorderdetailsRecords[i]);
                addNo++;
            }
            if (addNo >= size)
                break;
            // if (addNo >= size)
            //     break;
        }
        return consumableorderdetailsRecordsview;
    }
@@ -184,6 +188,7 @@
    @AuraEnabled
    public static Results init(String type, String esetId, String keywordStr) {
        Results results = new Results();
        results.isNoteStay = LexUtility.getIsNoteStay();
        errorMsgList = new List<String>();
        warningMsgList = new List<String>();
        baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
@@ -201,12 +206,12 @@
        pageLimit = Integer.valueOf(System.Label.orderdetPageLimitsize);
        ESetId = esetId;
        methodType = type;
        if(String.isBlank(methodType) && String.isNotBlank(ESetId)){
        if (String.isBlank(methodType) && String.isNotBlank(ESetId)) {
            List<Consumable_order__c> oclist = [SELECT orderPattern__c FROM Consumable_order__c WHERE id = :ESetid];
            methodType = oclist.get(0).orderPattern__c;
        }
        statusEdit = keywordStr;
        System.debug('Param:'+ESetId+'---'+methodType+'---'+statusEdit);
        System.debug('Param:' + ESetId + '---' + methodType + '---' + statusEdit);
        try {
            sortKey = '1';
            preSortKey = '1';
@@ -226,10 +231,20 @@
            }
            userId = UserInfo.getUserId();
            List<user> Useracc = new List<user>();
            Useracc = [SELECT accountid, Work_Location__c, UserPro_Type__c FROM user WHERE id = :userId];
            //lt 20230517 安徽两票制 add ,OSHFLG__c
            Useracc = [SELECT accountid, Work_Location__c, UserPro_Type__c, OSHFLG__c FROM user WHERE id = :userId];
            accountid = Useracc[0].accountid;
            userWorkLocation = Useracc[0].Work_Location__c;
            agencyProType = Useracc[0].UserPro_Type__c;
            agencyProType1 = Useracc[0].UserPro_Type__c; //lt 20230526 安徽两票制 add
            //lt 20230526 安徽两票制 start
            OSHFLG = Useracc[0].OSHFLG__c; //lt 20230517 安徽两票制 add
            if (OSHFLG) {
                agencyProType1 = 'OSH';
            } else if (String.isBlank(Useracc[0].UserPro_Type__c)) {
                agencyProType1 = 'ET';
            }
            //lt 20230526 安徽两票制 end
            if (String.isBlank(Useracc[0].UserPro_Type__c)) {
                agencyProType = 'ET';
            }
@@ -248,8 +263,9 @@
                    RecordType.DeveloperName = 'AgencyContract'
                    AND Contract_Decide_Start_Date__c <= :dateToday
                    AND Contract_Decide_End_Date__c >= :dateToday
                    AND Contact_Type__c LIKE :agencyProType
                    AND Contact_Type__c LIKE :agencyProType1 //lt 20230517 安徽两票制 add 1
                    AND Agent_Ref__c = :accountid
                    AND OSH_Dealer__c = :OSHFLG //lt 20230517 安徽两票制 add
            ];
            for (Account contract : contractList) {
                contactDealer.add(contract.Id);
@@ -313,9 +329,10 @@
                    FROM Account
                    WHERE
                        ParentId = :accountid
                        AND Contact_Type__c LIKE :agencyProType
                        AND Contact_Type__c LIKE :agencyProType1 //lt 20230517 安徽两票制 add 1
                        AND Contract_Decide_Start_Date__c <= :Date.Today()
                        AND Contract_Decide_End_Date__c >= :Date.Today()
                        AND OSH_Dealer__c = :OSHFLG //lt 20230517 安徽两票制 add
                ];
                if (contract.size() == 1) {
                    contractName = contract[0].Name;
@@ -364,7 +381,16 @@
                }
                consumableorderdetailsRecords.sort();
                if (methodType != null && methodType != '' && (methodType.equals('hospitalorder') || methodType.equals('promotionorder'))) {
                    searchorderdetails(methodType,accountid,hospitalId,contractId,userWorkLocation,accountName,proLimitAndDate,editAble);
                    searchorderdetails(
                        methodType,
                        accountid,
                        hospitalId,
                        contractId,
                        userWorkLocation,
                        accountName,
                        proLimitAndDate,
                        editAble
                    );
                    isfirst = true;
                }
                getPageInfo();
@@ -440,9 +466,12 @@
                        AND Consumable_order__r.Dealer_Info__c = :accountid
                ];
                for (Consumable_Orderdetails__c cdc1 : ConsumableorderdetailsSelected) {
                    orderzaikuId.add(cdc1.Consumable_Product__c);
                    if (cdc1.Consumable_Product__c != null) {
                        orderzaikuId.add(cdc1.Consumable_Product__c);
                    }
                }
                soql = makeSoqlorderdet();
                System.debug('soql:' + soql);
                size = orderzaikuId.size();
                initStandardController();
                product2Selected = Database.query(soql);
@@ -516,12 +545,30 @@
                    }
                }
                //附件
                attachmentinfo = [SELECT Id, Name, OwnerId, Owner.Name FROM Attachment WHERE parentid = :ESetId];
                if (attachmentinfo.size() > 0) {
                    for (Integer i = 0; i < attachmentinfo.size(); i++) {
                        attachmentRecoeds.add(new ConsumableorderdetailsInfo(attachmentinfo[i]));
                // attachmentinfo = [SELECT Id, Name, OwnerId, Owner.Name FROM Attachment WHERE parentid = :ESetId];
                // if (attachmentinfo.size() > 0) {
                //     for (Integer i = 0; i < attachmentinfo.size(); i++) {
                //         attachmentRecoeds.add(new ConsumableorderdetailsInfo(attachmentinfo[i]));
                //     }
                // }
                List<ContentDocumentLink> links = [SELECT Id, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :ESetId];
                if (links != null && links.size() > 0) {
                    List<String> documentIds = new List<String>();
                    for (ContentDocumentLink link : links) {
                        documentIds.add(link.ContentDocumentId);
                    }
                    List<ContentVersion> cvInfo = [
                        SELECT Id, Title, OwnerId, Owner.Name, CreatedDate, ContentDocumentId
                        FROM ContentVersion
                        WHERE ContentDocumentId IN :documentIds
                    ];
                    if (cvInfo.size() > 0) {
                        for (Integer i = 0; i < cvInfo.size(); i++) {
                            attachmentRecoeds.add(new ConsumableorderdetailsInfo(cvInfo[i]));
                        }
                    }
                }
                //
                consumableorderdetailsRecords.sort();
                getPageInfo();
            }
@@ -532,8 +579,10 @@
            List<String> upper = new List<String>();
            if (String.isNotBlank(ESetid)) {
                for (ConsumableorderdetailsInfo bss : consumableorderdetailsRecords) {
                    if (bss.esd.Consumable_count__c + bss.allnumber > bss.upperlimit) {
                        upper.add(bss.esd.Consumable_Product__r.Name__c);
                    if (bss.esd.Consumable_count__c != null && bss.allnumber != null && bss.upperlimit != null) {
                        if (bss.esd.Consumable_count__c + bss.allnumber > bss.upperlimit) {
                            upper.add(bss.esd.Consumable_Product__r.Name__c);
                        }
                    }
                }
            }
@@ -566,23 +615,24 @@
            // categoryOptionList = new List<SelectOption>();
            category3Option = new List<CusOption>();
            // categoryOptionList.add(new SelectOption('', '-无-'));
            category3Option.add(new CusOption('-无-',''));
            category3Option.add(new CusOption('-无-', ''));
            for (AggregateResult category3Search : categoryList) {
                String deliverycnt = String.valueOf(category3Search.get('c3c'));
                // categoryOptionList.add(new SelectOption(deliverycnt, deliverycnt));
                category3Option.add(new CusOption(deliverycnt,deliverycnt));
                category3Option.add(new CusOption(deliverycnt, deliverycnt));
            }
            //categoty4
            // category4OptionList = new List<SelectOption>();
            category4Option = new List<CusOption>();
            // category4OptionList.add(new SelectOption('', '-无-'));
            category4Option.add(new CusOption('-无-',''));
            category4Option.add(new CusOption('-无-', ''));
            //categoty5
            // category5OptionList = new List<SelectOption>();
            category5Option = new List<CusOption>();
            // category5OptionList.add(new SelectOption('', '-无-'));
            category5Option.add(new CusOption('-无-',''));
            category5Option.add(new CusOption('-无-', ''));
            //return msg
            consumableorderdetailsRecordsview = consumableorderdetailsRecords;
            getConsumableShowTableFieldValue();
            results.result = 'Success';
            results.coc = coc;
@@ -598,6 +648,8 @@
            results.attachmentRecoeds = attachmentRecoeds;
            results.cansee = cansee;
            results.agencyProType = agencyProType;
            results.agencyProType1 = agencyProType1;
            results.OSHFLG = OSHFLG;
            results.userWorkLocation = userWorkLocation;
            results.accountName = accountName;
            results.category_Goods = category_Goods;
@@ -619,7 +671,7 @@
    }
    @AuraEnabled
    public static Results categoryAllload(String agencyProTypeStr, String category3Str){
    public static Results categoryAllload(String agencyProTypeStr, String category3Str) {
        Results results = new Results();
        agencyProType = agencyProTypeStr;
        category3 = category3Str;
@@ -675,7 +727,7 @@
    }
    @AuraEnabled
    public static Results categoryload(String agencyProTypeStr, String category3Str, String category4Str){
    public static Results categoryload(String agencyProTypeStr, String category3Str, String category4Str) {
        Results results = new Results();
        agencyProType = agencyProTypeStr;
        category3 = category3Str;
@@ -701,7 +753,7 @@
                // category4OptionList.add(new SelectOption(deliverycnt4, deliverycnt4));
                category4Option.add(new CusOption(deliverycnt4, deliverycnt4));
            }
            AggregateResult[] category5List = [
                SELECT Count(id), Category5_text__c c5c
                FROM Product2__c
@@ -829,300 +881,6 @@
        }
    }
    //库存排序
    public static void SortStore() {
        if (sortKey == preSortKey) {
            // 方向が変わるのみ
            sortOrderAsc = !sortOrderAsc;
            sortOrder[Integer.valueOf(sortKey)] = (sortOrderAsc == true ? '↑' : '↓');
        } else {
            sortOrderAsc = true;
            sortOrder[Integer.valueOf(preSortKey)] = ' ';
            sortOrder[Integer.valueOf(sortKey)] = (sortOrderAsc == true ? '↑' : '↓');
        }
        preSortKey = sortKey;
        List<ConsumableorderdetailsInfo> selectedSort = new List<ConsumableorderdetailsInfo>();
        List<ConsumableorderdetailsInfo> noselectedSort = new List<ConsumableorderdetailsInfo>();
        for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview) {
            ass.sortBy = sortOrderAsc;
            if (ass.check == true) {
                selectedSort.add(ass);
            } else {
                noselectedSort.add(ass);
            }
        }
        consumableorderdetailsRecordsview = new List<ConsumableorderdetailsInfo>();
        if (selectedSort.size() > 0) {
            if (searchDone != 'searchDone') {
                selectedSort.sort();
            }
            consumableorderdetailsRecordsview.addAll(selectedSort);
        }
        if (noselectedSort.size() > 0) {
            noselectedSort.sort();
            consumableorderdetailsRecordsview.addAll(noselectedSort);
        }
    }
    //限制性排序
    public static void SortLimited() {
        List<ConsumableorderdetailsInfo> reSet = new List<ConsumableorderdetailsInfo>();
        Map<String, ConsumableorderdetailsInfo> MidMap = new Map<String, ConsumableorderdetailsInfo>();
        List<Consumable_order_details2__c> countDel = [
            SELECT
                Id,
                Bar_Code__c,
                Name,
                Inventory_date__c,
                Consumable_Product__c,
                Consumable_Product__r.Asset_Model_No__c,
                Recordtypeid,
                Box_Piece__c,
                hospitalSpecialOffer__c,
                promotionorder__c
            FROM Consumable_order_details2__c
            WHERE
                Dealer_Arrive__c = TRUE
                AND Dealer_Shipment__c = FALSE
                AND Dealer_Saled__c = FALSE
                AND Dealer_Returned__c = FALSE
                AND Lose_Flag__c = FALSE
                AND Bar_Code__c != NULL
                AND Arrive_Owner_Work_Location__c = :userWorkLocation
                //AND Consumable_order_minor__r.Dealer_Info__c = :accountid
                AND Dealer_Info_text__c = :accountName
        ];
        if (sortKey == preSortKey) {
            // 方向が変わるのみ
            sortOrderAsc = !sortOrderAsc;
            sortOrder[Integer.valueOf(sortKey)] = (sortOrderAsc == true ? '↓' : '↑');
        } else {
            sortOrderAsc = true;
            sortOrder[Integer.valueOf(preSortKey)] = ' ';
            sortOrder[Integer.valueOf(sortKey)] = (sortOrderAsc == true ? '↓' : '↑');
        }
        preSortKey = sortKey;
        // 所有产品取得
        if (
            (EsetId == null || ESetId == '') || (EsetId != null && ESetId != '' && statusEdit == 'Redirect' && searchDone == 'searchDone')
        ) {
            String strProd = null;
            for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview) {
                if (strProd == null || strProd.length() == 0) {
                    strProd = '\'' + String.valueOf(ass.prod.Id) + '\'';
                } else {
                    strProd += ',\'' + String.valueOf(ass.prod.Id) + '\'';
                }
            }
            String soqll = 'SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,Product2__r.Packing_list_manual__c,Category3__c,Category4__c,Category5__c FROM Product2__c WHERE Estimation_Entry_Possibility__c = \'○\' ';
            //update by rentx 2020-12-31 start
            if (agencyProType == 'ET') {
                soqll += ' AND Pro2_Dealer_Object__c = true';
            }
            if (agencyProType == 'ENG') {
                soqll += ' AND Pro2_Dealer_ENG__c = true';
            }
            soqll += ' AND Intra_Trade_List_RMB__c > 0 ';
            //update by rentx 2020-12-31 end
            soqll += ' AND Id IN (' + strProd + ')';
            soqll +=
                ' order by ' +
                columus_no[Integer.valueOf(sortKey)] +
                ' ' +
                (sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
            List<Product2__c> queryList = Database.query(soqll);
            // 選択済みの明细を取得
            Map<String, String> selectedIdMap = new Map<String, String>();
            for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview) {
                if (ass.check == true) {
                    selectedIdMap.put(ass.Prod.id, ass.Prod.id);
                    reSet.add(ass);
                }
            }
            for (Integer i = 0; i < queryList.size(); i++) {
                if (selectedIdMap.containsKey(queryList[i].Id)) {
                    // 跳过已经选择的消耗品明细
                    continue;
                } else {
                    // 未选择的消耗品明细
                    MidMap.put(queryList[i].Id, new ConsumableorderdetailsInfo(queryList[i]));
                }
            }
            consumableorderdetailsRecordsview = new List<ConsumableorderdetailsInfo>();
            consumableorderdetailsRecordsview = reSet;
            for (Integer i = 0; i < countDel.size(); i++) {
                if (String.isNotBlank(methodType) && methodType.equals('hospitalorder')) {
                    if (countDel[i].hospitalSpecialOffer__c == true) {
                        //然后循环CountDel去修改map里的allnumber
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
                                Jstage.allnumber_piece = Jstage.allnumber_piece + 1;
                            }
                            MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                        }
                    }
                } else if (String.isBlank(methodType) || methodType.equals('promotionorder')) {
                    if (countDel[i].promotionorder__c == true) {
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
                                Jstage.allnumber_piece = Jstage.allnumber_piece + 1;
                            }
                            MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                        }
                    }
                } else if (String.isBlank(methodType) || (!methodType.equals('promotionorder') && !methodType.equals('hospitalorder'))) {
                    if (countDel[i].promotionorder__c == false && countDel[i].hospitalSpecialOffer__c == false) {
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
                                Jstage.allnumber_piece = Jstage.allnumber_piece + 1;
                            }
                            MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                        }
                    }
                }
            }
            //把map里的值从新赋给ConsumableorderdetailsRecords
            for (ConsumableorderdetailsInfo bss : MidMap.values()) {
                if (selectedIdMap.containsKey(bss.Prod.Id)) {
                    continue;
                } else {
                    if (DealerProductMap.containsKey(bss.Prod.Id)) {
                        bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id).Special_Campaign_Price__c;
                        bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id).Campaign_EndDate__c;
                        bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id).OrderGoods_Limit__c;
                    }
                    bss.packing_list = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                    consumableorderdetailsRecordsview.add(bss);
                }
            }
        } else if (searchDone != 'searchDone') {
            String strProd = null;
            for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview) {
                if (strProd == null || strProd.length() == 0) {
                    strProd = '\'' + String.valueOf(ass.prod.Id) + '\'';
                } else {
                    strProd += ',\'' + String.valueOf(ass.prod.Id) + '\'';
                }
            }
            String SqlOrder = 'SELECT Id,  Name, Consumable_order__c, Consumable_Product__r.Name__c,';
            SqlOrder += ' Consumable_Product__c,Consumable_Product__r.Name,';
            SqlOrder += 'Consumable_Count__c,Consumable_Product__r.Intra_Trade_List_RMB__c,';
            SqlOrder += 'Consumable_Product__r.Asset_Model_No__c,Sum_of_money__c, ';
            SqlOrder += 'Consumable_Product__r.SFDA_Status__c,Consumable_Product__r.Product2__r.Packing_list_manual__c,Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,';
            SqlOrder += 'Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c,Consumable_Product__r.Category3__c,Consumable_Product__r.Category4__c,Consumable_Product__r.Category5__c ';
            SqlOrder +=
                'FROM Consumable_orderdetails__c WHERE recordtypeid != \'' +
                System.Label.RT_ConOrderDetail1_Sale +
                '\' AND  Consumable_order__c = \'' +
                ESetId +
                '\'';
            SqlOrder += ' AND Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' ';
            SqlOrder += ' AND Consumable_Product__c IN (' + strProd + ')';
            SqlOrder +=
                ' order by ' +
                columus[Integer.valueOf(sortKey)] +
                ' ' +
                (sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
            List<Consumable_Orderdetails__c> queryList = Database.query(SqlOrder);
            // 選択済みの明细を取得
            Map<String, String> selectedIdMap = new Map<String, String>();
            for (Integer i = 0; i < queryList.size(); i++) {
                // 未选择的消耗品明细
                MidMap.put(queryList[i].Consumable_Product__c, new ConsumableorderdetailsInfo(queryList[i]));
            }
            for (Integer i = 0; i < countDel.size(); i++) {
                if (String.isNotBlank(methodType) && methodType.equals('hospitalorder')) {
                    if (countDel[i].hospitalSpecialOffer__c == true) {
                        //然后循环CountDel去修改map里的allnumber
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
                                Jstage.allnumber_piece = Jstage.allnumber_piece + 1;
                            }
                            MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                        }
                    }
                } else if (String.isBlank(methodType) || methodType.equals('promotionorder')) {
                    if (countDel[i].promotionorder__c == true) {
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
                                Jstage.allnumber_piece = Jstage.allnumber_piece + 1;
                            }
                            MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                        }
                    }
                } else if (String.isBlank(methodType) || (!methodType.equals('promotionorder') && !methodType.equals('hospitalorder'))) {
                    if (countDel[i].promotionorder__c == false && countDel[i].hospitalSpecialOffer__c == false) {
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
                                Jstage.allnumber_piece = Jstage.allnumber_piece + 1;
                            }
                            MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                        }
                    }
                }
            }
            consumableorderdetailsRecordsview = new List<ConsumableorderdetailsInfo>();
            //把map里的值从新赋给ConsumableorderdetailsRecords
            for (ConsumableorderdetailsInfo bss : MidMap.values()) {
                if (DealerProductMap.containsKey(bss.Prod.Id)) {
                    bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id).Special_Campaign_Price__c;
                    bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id).Campaign_EndDate__c;
                    bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id).OrderGoods_Limit__c;
                }
                bss.packing_list = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                consumableorderdetailsRecordsview.add(bss);
            }
        }
        productLimtAndDateView();
    }
    //库存上下限
    public static void productLimtAndDateView() {
        String nowName = null, nowRightAsstModelNo = null;
        Map<String, String> productLimt = new Map<String, String>();
        for (Integer i = 0; i < proLimitAndDate.size(); i++) {
            nowName = proLimitAndDate[i];
            if (nowName.indexOf('|') >= 0) {
                nowRightAsstModelNo = nowName.subString(0, nowName.indexOf('|'));
                nowName = nowName.subString(nowName.indexOf('|') + 1);
            }
            productLimt.put(nowRightAsstModelNo, nowName);
        }
        for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview) {
            if (productLimt.containsKey(ass.Prod.Asset_Model_No__c)) {
                ass.lowerlimit = decimal.valueOf(
                    productLimt.get(ass.Prod.Asset_Model_No__c).subString(0, productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|'))
                );
                ass.upperlimit = decimal.valueOf(
                    productLimt.get(ass.Prod.Asset_Model_No__c).subString(productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|') + 1)
                );
            }
        }
    }
    //库存上下限
    public static void productLimtAndDate() {
        String nowName = null, nowRightAsstModelNo = null;
@@ -1188,8 +946,9 @@
        String dealerProductIdStr,
        String methodTypeStr,
        String consumableorderdetailsRecordsviewStr,
        Boolean editAbleStr
    ){
        Boolean editAbleStr,
        List<String> proLimitAndDateList
    ) {
        Results results = new Results();
        errorMsgList = new List<String>();
        warningMsgList = new List<String>();
@@ -1207,8 +966,12 @@
        specialCampaign = specialCampaignStr;
        methodType = methodTypeStr;
        editAble = editAbleStr;
        dealerProductId = (List<String>)JSON.deserialize(dealerProductIdStr, List<String>.class);
        consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>)JSON.deserialize(consumableorderdetailsRecordsviewStr, List<ConsumableorderdetailsInfo>.class);
        proLimitAndDate = proLimitAndDateList;
        dealerProductId = (List<String>) JSON.deserialize(dealerProductIdStr, List<String>.class);
        consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>) JSON.deserialize(
            consumableorderdetailsRecordsviewStr,
            List<ConsumableorderdetailsInfo>.class
        );
        size = Integer.valueOf(System.Label.orderdetLimitsize);
        pageLimit = Integer.valueOf(System.Label.orderdetPageLimitsize);
        try {
@@ -1252,7 +1015,7 @@
            soql = makeSoql(category1, category_Goods, category3, category4, category5, specialCampaign, DealerProductId);
            size = Integer.valueOf(System.Label.orderdetLimitsize);
            initStandardController();
            System.debug('soql:'+soql);
            System.debug('soql:' + soql);
            product2Selected = Database.query(soql);
            for (Integer i = 0; i < product2Selected.size(); i++) {
                MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
@@ -1327,12 +1090,12 @@
            // makeMessage();
            results.errorMsgList = errorMsgList;
            results.warningMsgList = warningMsgList;
            if(consumableorderdetailsRecordsview.size() > 0){
            if (consumableorderdetailsRecords.size() > 0) {
                getConsumableShowTableFieldValue();
                results.result = 'Success';
                results.consumableorderdetailsRecordsview = consumableorderdetailsRecordsview;
                results.errorMsg = '搜索到' + consumableorderdetailsRecordsview.size() + '件产品';
            }else {
                results.errorMsg = '搜索到' + consumableorderdetailsRecords.size() + '件产品';
            } else {
                getConsumableShowTableFieldValue();
                results.result = 'Fail';
                results.consumableorderdetailsRecordsview = consumableorderdetailsRecordsview;
@@ -1356,7 +1119,7 @@
        String accountNameStr,
        List<String> proLimitAndDateList,
        Boolean editAbleStr
    ){
    ) {
        Results results = new Results();
        methodType = methodTypeStr;
        accountId = accountIdStr;
@@ -1382,7 +1145,7 @@
                    for (hospitalprice__c hc : hplist) {
                        hpids.add(hc.product__c);
                    }
                    if (hpids != null && hpids.size() > 0) {
                        soql += ' AND Id in : hpids ';
                    }
@@ -1507,10 +1270,10 @@
            noOfRecords = consumableorderdetailsRecords.size();
            getConsumableShowTableFieldValue();
            results.consumableorderdetailsRecordsview = consumableorderdetailsRecordsview;
            if(consumableorderdetailsRecordsview.size() > 0){
            if (consumableorderdetailsRecordsview.size() > 0) {
                results.result = 'Success';
                results.errorMsg = '共搜索到'+consumableorderdetailsRecordsview.size()+'条数据';
            }else {
                results.errorMsg = '共搜索到' + consumableorderdetailsRecordsview.size() + '条数据';
            } else {
                results.result = 'Fail';
                results.errorMsg = '没有搜索到相关数据';
            }
@@ -1537,18 +1300,20 @@
            if (selectedIdMap.containsKey(consumableorderdetailsRecords[i].Prod.Id)) {
                addNo++;
                //continue;
            } else if (consumableorderdetailsRecordsview.size() >= pageLimit + size) {
                break;
            } else {
            }
            // else if (consumableorderdetailsRecordsview.size() >= pageLimit + size) {
            //     break;
            // }
            else {
                if (consumableorderdetailsRecords[i].check == false) {
                    consumableorderdetailsRecords[i].esd = orderdetails1;
                }
                consumableorderdetailsRecordsview.add(consumableorderdetailsRecords[i]);
                addNo++;
            }
            if (addNo >= size){
                break;
            }
            // if (addNo >= size){
            //     break;
            // }
        }
        return consumableorderdetailsRecordsview;
    }
@@ -1699,6 +1464,8 @@
            }
        }
        String soql = 'SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,Product2__r.Packing_list_manual__c,Category3__c,Category4__c,Category5__c FROM Product2__c WHERE Estimation_Entry_Possibility__c = \'○\' ';
        System.debug('sqlTail:' + sqlTail);
        System.debug('orderzaikuId:' + orderzaikuId);
        if (orderzaikuId.size() > 0) {
            soql += ' AND Id in' + sqlTail;
        }
@@ -1707,7 +1474,7 @@
    // 编辑按钮
    @AuraEnabled
    public static Results setEditAble(String eSetidStr){
    public static Results setEditAble(String eSetidStr) {
        Results results = new Results();
        ESetId = eSetidStr;
        try {
@@ -1749,12 +1516,16 @@
        Results results = new Results();
        try {
            base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
            Blob contentBlob = EncodingUtil.base64Decode(base64Data);
            Attachment att = new Attachment();
            att.ParentId = pId;
            att.Name = fileName;
            att.Body = contentBlob;
            insert att;
            ContentVersion cv = new ContentVersion();
            cv.Title = fileName;
            cv.PathOnClient = '/' + fileName;
            cv.FirstPublishLocationId = pId;
            cv.VersionData = EncodingUtil.base64Decode(base64Data);
            cv.IsMajorVersion = true;
            insert cv;
            Consumable_order__c c = [SELECT Id FROM Consumable_order__c WHERE Id = :pId];
            c.Consumable_pdf_insert_day__c = Date.today();
            update c;
            results.result = 'Success';
        } catch (Exception e) {
            results.result = 'Fail';
@@ -1765,7 +1536,7 @@
    //删除按钮
    @AuraEnabled
    public static Results delConsumable(String eSetidStr){
    public static Results delConsumable(String eSetidStr) {
        Results results = new Results();
        ESetId = eSetidStr;
        try {
@@ -1788,7 +1559,7 @@
    // 提交按钮
    @AuraEnabled
    public static Results sorder(String eSetidStr,String accountidStr){
    public static Results sorder(String eSetidStr, String accountidStr) {
        Results results = new Results();
        errorMsgList = new List<String>();
        warningMsgList = new List<String>();
@@ -1863,13 +1634,29 @@
        String consumableorderdetailsRecordsviewStr,
        String contactDealerStr,
        String methodTypeStr,
        String hospitalIdStr
        String hospitalIdStr,
        String contractIdStr,
        String agencyProType1Str,
        Boolean OSHFLGStr
    ) {
        ESetId = '';
        return save(contractNameStr,cocStr,agencyProTypeStr,accountidStr,consumableorderdetailsRecordsviewStr,contactDealerStr,methodType,ESetId,hospitalIdStr);
        return save(
            contractNameStr,
            cocStr,
            agencyProTypeStr,
            accountidStr,
            consumableorderdetailsRecordsviewStr,
            contactDealerStr,
            methodTypeStr,
            ESetId,
            hospitalIdStr,
            contractIdStr,
            agencyProType1Str,
            OSHFLGStr
        );
    }
    //保存按钮
    //保存按钮
    @AuraEnabled
    public static Results save(
        String contractNameStr,
@@ -1880,8 +1667,11 @@
        String contactDealerStr,
        String methodTypeStr,
        String eSetIdStr,
        String hospitalIdStr
    ){
        String hospitalIdStr,
        String contractIdStr,
        String agencyProType1Str,
        Boolean OSHFLGStr
    ) {
        Results results = new Results();
        errorMsgList = new List<String>();
        warningMsgList = new List<String>();
@@ -1891,12 +1681,19 @@
        methodType = methodTypeStr;
        ESetId = eSetIdStr;
        hospitalId = hospitalIdStr;
        coc = (Consumable_order__c)JSON.deserialize(cocStr, Consumable_order__c.class);
        contactDealer = (List<String>)JSON.deserialize(contactDealerStr, List<String>.class);
        consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>)JSON.deserialize(consumableorderdetailsRecordsviewStr, List<ConsumableorderdetailsInfo>.class);
        if(coc.Offers_Price__c != null){
        contractId = contractIdStr;
        agencyProType1 = agencyProType1Str;
        OSHFLG = OSHFLGStr;
        coc = (Consumable_order__c) JSON.deserialize(cocStr, Consumable_order__c.class);
        contactDealer = (List<String>) JSON.deserialize(contactDealerStr, List<String>.class);
        System.debug('consumableorderdetailsRecordsviewStr:' + consumableorderdetailsRecordsviewStr);
        consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>) JSON.deserialize(
            consumableorderdetailsRecordsviewStr,
            List<ConsumableorderdetailsInfo>.class
        );
        if (coc.Offers_Price__c != null) {
            String offerStr = String.valueOf(coc.Offers_Price__c);
            bargainPrice = Decimal.valueOf(offerStr.replace(',',''));
            bargainPrice = Decimal.valueOf(offerStr.replace(',', ''));
        }
        Savepoint sp = Database.setSavepoint();
        try {
@@ -1911,10 +1708,12 @@
                FROM account
                WHERE
                    Name = :contractName
                    AND Id = :contractId //lt 20230517 安徽两票制 add
                    AND Contract_Decide_Start_Date__c <= :Date.Today()
                    AND Contract_Decide_End_Date__c >= :Date.Today()
                    AND Contact_Type__c LIKE :agencyProType
                    AND Contact_Type__c LIKE :agencyProType1 //lt 20230517 安徽两票制 add 1
                    AND Agent_Ref__c = :accountid
                    AND OSH_Dealer__c = :OSHFLG //lt 20230517 安徽两票制 add
            ];
            if (contract.size() <= 0) {
                // coc.Order_effective_contact__c.addError('不存在的合同,请重新确认。');
@@ -1967,13 +1766,14 @@
            }
            //=======================================医院特价,有金额的话取金额
            Map<String, Decimal> dealerHospitalmMap = new Map<String, Decimal>();
            List<hospitalprice__c> hplist = [select Id,hospital__c,mPrice__c,pPrice__c,product__c,account__c
                                                from hospitalprice__c
                                                where product__c in :tpids and mPrice__c <> null and account__c=:accountid
                                                ];
            List<hospitalprice__c> hplist = [
                SELECT Id, hospital__c, mPrice__c, pPrice__c, product__c, account__c
                FROM hospitalprice__c
                WHERE product__c IN :tpids AND mPrice__c != NULL AND account__c = :accountid
            ];
            for (hospitalprice__c dealerProduct : hplist) {
                if (dealerProduct.mPrice__c != null) {
                    dealerHospitalmMap.put('' + dealerProduct.hospital__c + dealerProduct.product__c,dealerProduct.mPrice__c);
                if (dealerProduct.mPrice__c != null) {
                    dealerHospitalmMap.put('' + dealerProduct.hospital__c + dealerProduct.product__c, dealerProduct.mPrice__c);
                }
            }
            //促销订货 根据经销商产品中的数据计算金额
@@ -2055,9 +1855,13 @@
                FROM Account
                WHERE
                    Name = :contractName
                    AND Id = :contractId //lt 20230517 安徽两票制 add
                    AND Contact_Type__c LIKE :agencyProType1 //lt 20230517 安徽两票制 add  1
                    AND Contact_Type__c LIKE :agencyProType
                    AND Contract_Decide_Start_Date__c <= :Date.Today()
                    AND Contract_Decide_End_Date__c >= :Date.Today()
                    AND Contract_Decide_End_Date__c >= :Date.Today()
                    AND OSH_Dealer__c = :OSHFLG //lt 20230517 安徽两票制 add
            ];
            if (at.size() > 0 && at[0].Dealer_discount__c != null) {
                disCount = at[0].Dealer_discount__c;
@@ -2122,16 +1926,19 @@
                                        ass.Prod.Intra_Trade_List_RMB__c *
                                        dealerPDiscountMap.get('' + contract[0].Id + ass.Prod.Id) /
                                        100;
                                        system.debug('cai 00' + InsAfterDel.Intra_Trade_List_RMB__c);
                                    system.debug('cai 00' + InsAfterDel.Intra_Trade_List_RMB__c);
                                }
                                //=====================================================================================update by rentx 2020-11-25
                            } else if (methodType.equals('hospitalorder')) {
                                //医院特价
                                Consumable_order[0].Order_ForHospital__c = hospitalId;
                                Consumable_order[0].orderPattern__c = 'hospitalorder';
                                if (dealerHospitalmMap.containsKey(hospitalId + ass.Prod.Id) && dealerHospitalmMap.get(hospitalId + ass.Prod.Id) != null) {
                                if (
                                    dealerHospitalmMap.containsKey(hospitalId + ass.Prod.Id) &&
                                    dealerHospitalmMap.get(hospitalId + ass.Prod.Id) != null
                                ) {
                                    //直接根据促销金额计算
                                    InsAfterDel.Intra_Trade_List_RMB__c = dealerHospitalmMap.get(''+ hospitalId + ass.Prod.Id);
                                    InsAfterDel.Intra_Trade_List_RMB__c = dealerHospitalmMap.get('' + hospitalId + ass.Prod.Id);
                                }
                            } else if (DealerProductMap.containsKey(ass.Prod.Id)) {
                                InsAfterDel.Intra_Trade_List_RMB__c = DealerProductMap.get(ass.Prod.Id).Special_Campaign_Price__c;
@@ -2222,9 +2029,12 @@
                                Consumable_order[0].orderPattern__c = 'hospitalorder';
                                //医院特价
                                Consumable_order[0].Order_ForHospital__c = hospitalId;
                                if (dealerHospitalmMap.containsKey(hospitalId + ass.Prod.Id) && dealerHospitalmMap.get(hospitalId + ass.Prod.Id) != null) {
                                if (
                                    dealerHospitalmMap.containsKey(hospitalId + ass.Prod.Id) &&
                                    dealerHospitalmMap.get(hospitalId + ass.Prod.Id) != null
                                ) {
                                    //直接根据促销金额计算
                                    InsAfterDel.Intra_Trade_List_RMB__c = dealerHospitalmMap.get(''+ hospitalId + ass.Prod.Id);
                                    InsAfterDel.Intra_Trade_List_RMB__c = dealerHospitalmMap.get('' + hospitalId + ass.Prod.Id);
                                }
                            } else if (DealerProductMap.containsKey(ass.Prod.Id)) {
                                InsAfterDel.Intra_Trade_List_RMB__c = DealerProductMap.get(ass.Prod.Id).Special_Campaign_Price__c;
@@ -2252,12 +2062,36 @@
        return results;
    }
    public static void getConsumableShowTableFieldValue(){
        for(ConsumableorderdetailsInfo con :consumableorderdetailsRecordsview){
            if(con.Prod != null){
    //删除附件
    @AuraEnabled
    public static Results deleteAtt(String contentVersionId, String cocId) {
        Results results = new Results();
        try {
            List<ContentVersion> cvInfo = [SELECT Id FROM ContentVersion WHERE FirstPublishLocationId = :cocId];
            ContentVersion conVersion = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionId];
            String contentDocumentId = conVersion.ContentDocumentId;
            ContentDocument conDocument = [SELECT Id FROM ContentDocument WHERE Id = :contentDocumentId];
            delete conDocument;
            if (cvInfo.size() <= 1) {
                Consumable_order__c c = [SELECT Id FROM Consumable_order__c WHERE Id = :cocId];
                c.Consumable_pdf_insert_day__c = null;
                update c;
            }
            results.result = 'Success';
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }
    public static void getConsumableShowTableFieldValue() {
        for (ConsumableorderdetailsInfo con : consumableorderdetailsRecordsview) {
            if (con.Prod != null) {
                con.recordId = con.Prod.Id;
                if(!con.oldCheck){
                    con.prodName = con.Prod.Name;
                if (!con.oldCheck) {
                    con.prodName = con.Prod.Name__c;
                    // System.debug('ProdName:'+con.Prod.Id+'---'+con.Prod.Name__c);
                }
                con.prodSFDAStatus = con.Prod.SFDA_Status__c;
                con.prodCategory3 = con.Prod.Category3__c;
@@ -2265,16 +2099,16 @@
                con.prodCategory5 = con.Prod.Category5__c;
                con.prodIntraTradeList = con.Prod.Intra_Trade_List_RMB__c;
            }
            if(con.esd != null){
                if(con.oldCheck){
                    con.prodName = con.esd.Consumable_Product__r.Name__c;
                }
            if (con.esd != null) {
                // if(con.oldCheck){
                // con.prodName = con.esd.Consumable_Product__r.Name__c;
                // }
                con.consumableCount = con.esd.Consumable_count__c;
            }
        }
    }
    class ConsumableorderdetailsInfo implements Comparable {
    public class ConsumableorderdetailsInfo implements Comparable {
        @AuraEnabled
        public Boolean check { get; set; }
        @AuraEnabled
@@ -2298,7 +2132,7 @@
        @AuraEnabled
        public Boolean canSelect { get; set; }
        @AuraEnabled
        public Attachment Concc { get; set; }
        public ContentVersion Concc { get; set; }
        @AuraEnabled
        public Boolean sortBy { get; set; }
        @AuraEnabled
@@ -2328,7 +2162,6 @@
        @AuraEnabled
        public Decimal consumableCount { get; set; }
        // 已存产品明细
        public ConsumableorderdetailsInfo(Consumable_Orderdetails__c e) {
            check = true;
@@ -2352,7 +2185,7 @@
            allnumber_piece = 0;
        }
        //附件
        public ConsumableorderdetailsInfo(Attachment e) {
        public ConsumableorderdetailsInfo(ContentVersion e) {
            Concc = e;
        }
        // 排序Consumable_order__c
@@ -2460,6 +2293,12 @@
        public String methodType;
        @AuraEnabled
        public List<String> proLimitAndDate;
        @AuraEnabled
        public Boolean isNoteStay;
        @AuraEnabled
        public Boolean OSHFLG;
        @AuraEnabled
        public String agencyProType1;
    }
    public class CusOption {