public with sharing class EquipmentRentalExtendController { // 检索条件 public Rental_Apply__c searchCondition { get; set; } // 其他定值条件 public Rental_Apply_Equipment_Set__c finalDay { get; set; } // 适用 public User finalDayFrom { get; set; } // 最终期限开始 public User finalDayTo { get; set; } // 最终期限结束 public String ownerSearch { get; set; } // 所有者 public String returnIMFupdate {get; set;} public String userProfileName {get; set;} public boolean isStockUser {get; set;} // 分页用 SWAG-B9UBDP start public Integer currPage { get; set; } // 当前页 public Integer totalPage { get; set; } // 总页数 public Integer selctRecordNum { get { return Integer.valueOf(selRecordOption); } } // 选择的每页记录数 public Integer totalRecords { get; set; } // 总记录数 public String selRecordOption { get; set; } public static List recordNum { get; private set; } // 选择每页记录数List // 分页用 SWAG-B9UBDP end // 分页用 SWAG-B9UBDP start // 翻页到首页 public void firstPage() { currPage = 1; } // 向前翻页 public void previousPage() { currPage --; } // 向后翻页 public void nextPage() { currPage ++; } // 翻页到尾页 public void endPage() { currPage = totalPage; } // 每页显示记录数变更 public void recordNumChange() { currPage = 1; totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0); setupRaesInfoList(raesInfoList); } static { recordNum = new List(); recordNum.add(new SelectOption('10', '10')); recordNum.add(new SelectOption('20', '20')); recordNum.add(new SelectOption('50', '50')); recordNum.add(new SelectOption('100', '100')); recordNum.add(new SelectOption('200', '200')); } // 分页用 SWAG-B9UBDP end public static List textOpts { get; private set; } static { textOpts = new List(); textOpts.add(new SelectOption('', '-无-')); textOpts.add(new SelectOption('S:Rental_Apply__r.Name', Schema.SObjectType.Rental_Apply__c.fields.Name.label)); textOpts.add(new SelectOption('S:Loaner_name_F__c', Schema.SObjectType.Rental_Apply_Equipment_Set__c.fields.Loaner_name_F__c.label)); textOpts.add(new SelectOption('S:Loaner_code_F__c', Schema.SObjectType.Rental_Apply_Equipment_Set__c.fields.Loaner_code_F__c.label)); textOpts.add(new SelectOption('S:Rental_Apply__r.Hospital__r.Hospital_Name__c', Schema.SObjectType.Account.fields.Hospital_Name__c.label)); textOpts.add(new SelectOption('S:SerialNumber_F__c', Schema.SObjectType.Rental_Apply_Equipment_Set__c.fields.Rental_Asset_SerialNumber__c.label)); } public static List equalOpts { get; private set; } static { equalOpts = new List(); equalOpts.add(new SelectOption('equals', '等于')); equalOpts.add(new SelectOption('contains', '包含')); } public String text1 { get; set; } // 对象 public String cond1 { get; set; } // 条件 public String val1 { get; set; } // 值 /*****************ソートキー******************/ public String sortKey { get; set; } public String preSortKey { get; private set; } public Boolean sortOrderAsc { get; private set; } public String[] sortOrder { get; private set; } private String[] columus = new String[] { 'Rental_Apply__c', 'RAES_Status__c', 'Demo_purpose2__c', 'Loaner_code_F__c', 'Rental_Apply__r.Hospital__r.Hospital_Name__c', 'Final_reply_day__c', 'Demo_purpose1__c', 'Bollow_Date__c'}; private Boolean isSoft; private boolean isSearchAll; // 20210831 ljh SFDC-C4BBFH public String ExceedOrWeekDayFrom; // 预定归还日开始 public String ExceedOrWeekDayEnd; // 预定归还日结束 private boolean IsExceed;//超过中 private boolean IsWeek;// 1周以内回收预定 // 20210831 ljh SFDC-C4BBFH end /*****************ソート時再検索条件(画面からの入力条件を無視するため)******************/ private String text1ForSort = null; private String cond1ForSort = null; private String val1ForSort = null; private String purpose1ForSort = null; private Date fromDateForSort = null; private Date toDateForSort = null; private String ownerIdForSort = null; // 明细结果 public List raesInfoList { get; set; } // 明细条数 public Integer getRaesInfoListSize() { return raesInfoList.size(); } private String loginName; // 用户ID // 分页用 SWAG-B9UBDP start //private Integer Select_Limit = 200; // 显示数据条数限制 private Integer Select_Limit = 600; public List> raesInfoListList { get; set; } // 分页用 SWAG-B9UBDP end public EquipmentRentalExtendController(ApexPages.StandardController controller) { // 分页用 SWAG-B9UBDP start this(); // 分页用 SWAG-B9UBDP end } public EquipmentRentalExtendController() { // 分页用 SWAG-B9UBDP start currPage = 1; totalPage = 1; selRecordOption = '20'; totalRecords = 0; raesInfoListList = new List>(); raesInfoListList.add(new List()); // 分页用 SWAG-B9UBDP end } // 画面初始化 public void init() { returnIMFupdate = 'None'; searchCondition = new Rental_Apply__c(); finalDay = new Rental_Apply_Equipment_Set__c(); finalDayFrom = [select id, Birth_Date__c from User where id = :Userinfo.getUserId()]; finalDayFrom.Birth_Date__c = null; finalDayTo = [select id, Birth_Date__c from User where id = :Userinfo.getUserId()]; finalDayTo.Birth_Date__c = null; text1 = ''; cond1 = 'equals'; val1 = null; userProfileName = UserInfo.getProfileId(); if (userProfileName == System.Label.Profile_2B2)isStockUser = true; isSoft = false; isSearchAll = false; IsExceed = false;//20210816 ljh SFDC-C4BBFH 超过中 IsWeek = false;//20210816 ljh SFDC-C4BBFH 1周以内回收预定 loginName = null; // 获得用户ID String uidParam = System.currentPageReference().getParameters().get('uid'); if (uidParam != null) { // URL传入用户 User u = [select Id, FirstName, LastName from User where Id = :uidParam]; //ownerSearch = u.LastName + ' ' + u.FirstName; //20231105 sx 所有人修改 正式上线 start ownerSearch = u.LastName; ////20231105 sx 所有人修改 正式上线 end loginName = ownerSearch; } else { // 当前登陆用户 User u = [Select Id, FirstName, LastName From User Where Id = :UserInfo.getUserId()]; //ownerSearch = u.LastName + ' ' + u.FirstName; //20231105 sx 所有人修改 正式上线 start ownerSearch = u.LastName; //20231105 sx 所有人修改 正式上线 end loginName = ownerSearch; } raesInfoList = new List(); // 获取借出备品set一览 // 20210901 ljh SFDC-C4BBFH update start // List raesList = getData(text1, cond1, val1, searchCondition.Demo_purpose1__c, finalDayFrom.Birth_Date__c, finalDayTo.Birth_Date__c, ownerSearch); List raesList = getData(text1, cond1, val1, searchCondition.Demo_purpose1__c, finalDayFrom.Birth_Date__c, finalDayTo.Birth_Date__c, ownerSearch, ExceedOrWeekDayFrom,ExceedOrWeekDayEnd); // 20210901 ljh SFDC-C4BBFH update end // 作成明细行 getRaesInfoList(raesList); // 生成犯规信息 for (Rental_Apply_Equipment_Set__c rase : raesList) { } // 默认排序 this.sortKey = '0'; this.preSortKey = '0'; this.sortOrderAsc = true; this.sortOrder = new String[7]; this.sortOrder = new String[] {'↑', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; // 排序用检索条件退避 text1ForSort = ''; cond1ForSort = 'equals'; val1ForSort = null; purpose1ForSort = null; fromDateForSort = null; toDateForSort = null; ownerIdForSort = ownerSearch; } // 检索按钮 public PageReference searchBtn() { // 获取借出备品set一览 // List raesList = getData(text1, cond1, val1, searchCondition.Demo_purpose1__c, finalDayFrom.Birth_Date__c, finalDayTo.Birth_Date__c, ownerSearch); List raesList = getData(text1, cond1, val1, searchCondition.Demo_purpose1__c, finalDayFrom.Birth_Date__c, finalDayTo.Birth_Date__c, ownerSearch , ExceedOrWeekDayFrom,ExceedOrWeekDayEnd); // 20210827 ljh SFDC-C4BBFH add start List raesListNew = New List(); if(IsExceed || IsWeek){ for(Rental_Apply_Equipment_Set__c raes:raesList){ //Wei_Return_Finish__c if(raes.Wei_Return_Finish__c > 0){ raesListNew.add(raes); }else{ if(IsExceed && raes.Final_reply_day__c < raes.Return_Time_Day__c){ raesListNew.add(raes); } if(IsWeek && raes.Final_reply_day__c >= raes.Return_Time_Day__c){ raesListNew.add(raes); } } } }else{ raesListNew = raesList; } // 20210827 ljh SFDC-C4BBFH add end // 分页用 SWAG-B9UBDP start currPage = 1; // 分页用 SWAG-B9UBDP end // 作成明细行 // getRaesInfoList(raesList); getRaesInfoList(raesListNew); // 排序用检索条件退避 text1ForSort = text1; cond1ForSort = cond1; val1ForSort = val1; purpose1ForSort = searchCondition.Demo_purpose1__c; fromDateForSort = finalDayFrom.Birth_Date__c; toDateForSort = finalDayTo.Birth_Date__c; ownerIdForSort = ownerSearch; return null; } // 对明细行进行分页 private void setupRaesInfoList(List raesInfoList) { list> tempraesInfoListList = new list>(); List tempraesInfoList = new List(); for (RaesInfo tempRaesInfo : raesInfoList) { if (tempraesInfoList.size() >= selctRecordNum) { tempraesInfoListList.add(tempraesInfoList); tempraesInfoList = new List(); } tempraesInfoList.add(tempRaesInfo); } tempraesInfoListList.add(tempraesInfoList); totalPage = tempraesInfoListList.size(); if (tempraesInfoList.size() == 0) { totalPage --; } totalRecords = raesInfoList.size(); currPage = 1; raesInfoListList = tempraesInfoListList.clone(); } // 作成明细行 private void getRaesInfoList(List raesList) { Boolean overLimit = false; Set unReturnCompletely = new Set(); // 已经延期申请中的备品借出申请 Map rentalApplyMap = new Map(); for (Rental_Apply_Equipment_Set__c raes : raesList) { if (raes.Extend_Status__c == '申请中' && !rentalApplyMap.containsKey(raes.Rental_Apply__c)) { rentalApplyMap.put(raes.Rental_Apply__c, raes.Rental_Apply__c); } if (raes.Rental_Apply__r.Local_Borrow_Foul__c > 0) { unReturnCompletely.add(raes.Rental_Apply__r.Name); } } List raesIdList = new List(); // 已经打勾的明细保留并提前,但是要刷新最新状态 Map raesMap = new Map(); for (Rental_Apply_Equipment_Set__c raes : raesList) { raesMap.put(raes.Id, raes); raesIdList.add(raes.Id); } // 已经选择的明细 Map selectedMap = new Map(); for (RaesInfo info : raesInfoList) { // 打勾并且备品借出申请不是申请中的,或者刚刚进行延期申请的(特殊处理),视为优先显示明细 if ((info.check && !rentalApplyMap.containsKey(info.raes.Rental_Apply__c)) || info.isExtend) { selectedMap.put(info.raes.Id, raesMap.containsKey(info.raes.Id) ? raesMap.get(info.raes.Id) : info.raes); } } Map> resultRaesdMap = new Map>(); List RaasedList = [ select id , Rental_Apply_Equipment_Set__r.Id, Rental_Apply_Equipment_Set__r.SerialNumber_F__c , Rental_Apply_Equipment_Set__r.Fixture_Set__r.Loaner_code__c, Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name //, Asset__r.OwnershipMachine_No__c //, Asset__r.Name,Asset__r.Loaner_accsessary__c , OwnershipMachine_No_c__c , Asset__r.Name, Loaner_accsessary_F__c from Rental_Apply_Equipment_Set_Detail__c where Rental_Apply_Equipment_Set__r.Id in :raesIdList and Cancel_Select__c = False]; if (RaasedList != null) { for (Rental_Apply_Equipment_Set_Detail__c RaesdInfo : RaasedList) { if (resultRaesdMap.containsKey(RaesdInfo.Rental_Apply_Equipment_Set__r.Id)) { resultRaesdMap.get(RaesdInfo.Rental_Apply_Equipment_Set__r.Id).add(RaesdInfo); } else { List raList = New List(); raList.add(RaesdInfo); resultRaesdMap.put(RaesdInfo.Rental_Apply_Equipment_Set__r.Id, raList); } } } // 优先显示明细放在最前面 raesInfoList = new List(); List raesdList = New List(); for (Rental_Apply_Equipment_Set__c raes : selectedMap.values()) { raesdList = resultRaesdMap.get(raes.Id); RaesInfo raesinfo = new RaesInfo(true, raes, true, raesdList); raesInfoList.add(raesinfo); } raesInfoList.sort(); Integer selectCnt = raesInfoList.size(); // 其他明细作成 for (Integer i = 0; i < raesList.size(); i++) { // 201を超えた場合前200のみを出す if (selectCnt + i >= Select_Limit) {overLimit = true; break;} raesdList = resultRaesdMap.get(raesList[i].Id); // 作成明细行 if (!selectedMap.containsKey(raesList[i].Id)) { if (rentalApplyMap.containsKey(raesList[i].Rental_Apply__c)) { // 延长申请中的备品借出申请,不能操作 RaesInfo raesinfo = new RaesInfo(false, raesList[i], false, raesdList); raesInfoList.add(raesinfo); } else { // 其他备品借出申请,可以操作 RaesInfo raesinfo = new RaesInfo(false, raesList[i], true, raesdList); raesInfoList.add(raesinfo); } } } // 显示数据条数信息 if (returnIMFupdate != 'None') { //for(String Str : unReturnCompletely){ // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, Str )); //} //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '以上备品申请未整单归还,计入违规' )); } if (overLimit) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '数据超过' + Select_Limit + '条,只显示前' + Select_Limit + '条')); } else { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有' + getRaesInfoListSize() + '条数据')); } // 分页用 SWAG-B9UBDP start setupRaesInfoList(raesInfoList); // 分页用 SWAG-B9UBDP end } // 貸出中全部 public void searchsp1Btn() { isSearchAll = false; IsExceed = false;//20210816 ljh SFDC-C4BBFH 超过中 IsWeek = false;//20210816 ljh SFDC-C4BBFH 1周以内回收预定 // 设定对应检索条件 text1 = ''; cond1 = 'equals'; val1 = null; searchCondition.Demo_purpose1__c = null; finalDayFrom.Birth_Date__c = null; finalDayTo.Birth_Date__c = null; // 检索 searchBtn(); } // 超過中 public void searchsp2Btn() { isSearchAll = false; // 设定对应检索条件 text1 = ''; cond1 = 'equals'; val1 = null; searchCondition.Demo_purpose1__c = null; finalDayFrom.Birth_Date__c = null; // 20210628 ljh update SFDC-C4BBFH start // finalDayTo.Birth_Date__c = Date.today(); finalDayTo.Birth_Date__c = null; ExceedOrWeekDayFrom = null; // 开始 ExceedOrWeekDayEnd = String.valueOf(Date.today());// 结束 IsExceed = true; IsWeek = false; // 20210628 ljh update SFDC-C4BBFH end // 检索 searchBtn(); } // 1週間以内 public void searchsp3Btn() { isSearchAll = false; // 设定对应检索条件 text1 = ''; cond1 = 'equals'; val1 = null; searchCondition.Demo_purpose1__c = null; // 20210628 ljh update SFDC-C4BBFH start // finalDayFrom.Birth_Date__c = Date.today(); // finalDayTo.Birth_Date__c = Date.today().adddays(7); ExceedOrWeekDayFrom = String.valueOf(Date.today()); // 开始 ExceedOrWeekDayEnd = String.valueOf(Date.today().adddays(7)); // 结束 finalDayFrom.Birth_Date__c = null; finalDayTo.Birth_Date__c = null; IsExceed = false; //【超过中】 IsWeek = true; // 【1周以内回收预定】 // 20210628 ljh update SFDC-C4BBFH end // 检索 searchBtn(); } // 全部 public void searchsp4Btn() { isSearchAll = true; IsExceed = false;//20210816 ljh SFDC-C4BBFH 超过中 IsWeek = false;//20210816 ljh SFDC-C4BBFH 1周以内回收预定 // 设定对应检索条件 text1 = ''; cond1 = 'equals'; val1 = null; searchCondition.Demo_purpose1__c = null; finalDayFrom.Birth_Date__c = null; finalDayTo.Birth_Date__c = null; // 检索 searchBtn(); } // 明细排序 public void sortTable() { // 排序 if (this.sortKey == this.preSortKey) { // 方向が変わるのみ this.sortOrderAsc = !this.sortOrderAsc; this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓'); } else { if (preSortKey == '') { preSortKey = '0'; } this.sortOrderAsc = true; this.sortOrder[Integer.valueOf(this.preSortKey)] = ' '; this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓'); } this.preSortKey = this.sortKey; // 获取排序后借出备品set一览 isSoft = true; system.debug('IsExceed:'+IsExceed+'~'+IsWeek); // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, 'IsExceed。IsWeek' + IsExceed+IsWeek)); // 20210901 ljh SFDC-C4BBFH update start // List raesList = getData(text1ForSort, cond1ForSort, val1ForSort, purpose1ForSort, fromDateForSort, toDateForSort, ownerIdForSort); List raesList = getData(text1ForSort, cond1ForSort, val1ForSort, purpose1ForSort, fromDateForSort, toDateForSort, ownerIdForSort, ExceedOrWeekDayFrom,ExceedOrWeekDayEnd); List raesListNew = New List(); if(IsExceed || IsWeek){ for(Rental_Apply_Equipment_Set__c raes:raesList){ //Wei_Return_Finish__c if(raes.Wei_Return_Finish__c > 0){ raesListNew.add(raes); }else{ if(IsExceed && raes.Final_reply_day__c < raes.Return_Time_Day__c){ raesListNew.add(raes); } if(IsWeek && raes.Final_reply_day__c >= raes.Return_Time_Day__c){ raesListNew.add(raes); } } } }else{ raesListNew = raesList; } // 作成明细行 // getRaesInfoList(raesList); getRaesInfoList(raesListNew); // 20210827 ljh SFDC-C4BBFH add end } // 适用按钮 public void setDate() { // 检索,选择的明细优先显示 searchBtn(); // 打勾的明细自动填入适用的值 for (RaesInfo info : raesInfoList) { if (info.check == true) { info.raes.Request_extend_day__c = finalDay.Request_extend_day__c; info.raes.Extend_request_reason__c = finalDay.Extend_request_reason__c; } } } // 保存按钮 public PageReference saveBtn() { // 回寄物流信息检查 boolean errflg = false; //bp2 for (RaesInfo info : raesInfoList) { // // if (info.check && (info.raes.Return_Fedex_number2__c != null && info.raes.Return_Fedex_number2__c != '' || // info.raes.Return_delivery_company2__c != null || // info.raes.Return_Distributor_method2__c != null || // info.raes.Received_confirmation_staff2__c != null) // ) { // if (info.raes.Return_Fedex_number2__c == null || // info.raes.Return_Fedex_number2__c == '') { // info.raes.Return_Fedex_number2__c.addError('请补全回寄物流信息'); // errflg = true; // } // if (info.raes.Return_delivery_company2__c == null) { // info.raes.Return_delivery_company2__c.addError('请补全回寄物流信息'); // errflg = true; // } // if (info.raes.Return_Distributor_method2__c == null) { // info.raes.Return_Distributor_method2__c.addError('请补全回寄物流信息'); // errflg = true; // } // if (info.raes.Received_confirmation_staff2__c == null) { // info.raes.Received_confirmation_staff2__c.addError('请补全回寄物流信息'); // errflg = true; // } // } // } // if (errflg == true) { // return null; // } // 打勾的明细,保存延期时间和延期理由 List updateList = new List(); //bp2 List updateList2 = new List(); for (RaesInfo info : raesInfoList) { if (info.check) { Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(Id = info.raes.Id); //bp2 // raes.Request_extend_day__c = info.raes.Request_extend_day__c; // raes.Extend_request_reason__c = info.raes.Extend_request_reason__c; raes.Received_Confirm__c = info.raes.Received_Confirm__c; raes.Received_ng_detail__c = info.raes.Received_ng_detail__c; // OLY_OCM-460 Loaner_received_time__c的设置移动到Trigger //bp2 // raes.Return_delivery_company2__c = info.raes.Return_delivery_company2__c; // raes.Return_Fedex_number2__c = info.raes.Return_Fedex_number2__c; // raes.Return_Distributor_method2__c = info.raes.Return_Distributor_method2__c; // raes.Received_confirmation_staff2__c = info.raes.Received_confirmation_staff2__c; // if (info.raes.Return_Fedex_number2__c == null) { // raes.Asset_return_time__c = null; // } updateList.add(raes); //bp2 // Equipment_Set__c es = new Equipment_Set__c(Id=info.raes.Equipment_Set__c); // es.Return_delivery_company__c = info.raes.Return_delivery_company2__c; // es.Return_Fedex_number__c = info.raes.Return_Fedex_number2__c; // es.Return_Distributor_method__c = info.raes.Return_Distributor_method2__c; // es.Received_confirmation_staff__c = info.raes.Received_confirmation_staff2__c; // if (info.raes.Return_Fedex_number2__c == null) { // es.Received_loaner_time__c = null; // } // updateList2.add(es); } } System.debug('raes is' + updateList); // 更新 if (updateList.size() > 0) { try { //update updateList;//2017/1/12之前,该更新操作位于Savepoint内部,但发现会导致个别工作流无法出发 FixtureUtil.withoutUpdate(updateList); } catch (Exception e) { //故将其外移,注此说明,以备后查 ApexPages.addMessages(e); return null; } //bp2 // Savepoint sp = Database.setSavepoint(); // try { // ControllerUtil.updEquipmentSetList(updateList2); ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, '保存完了')); //bp2 // } catch (Exception e) { // system.debug('=====' + e.getMessage()); // ApexPages.addMessages(e); // Database.rollback(sp); // return null; // } } // 检索,选择的明细优先显示 searchBtn(); return null; } //bp2 // // 延期申请按钮 // public PageReference extendBtn() { // // 检索,选择的明细优先显示 // searchBtn(); // // 选择的明细中第一条的备品借出申请ID //// String raid = ''; //// if (raesInfoList.size() > 0) { //// raid = raesInfoList[0].raes.Rental_Apply__c; //// } // // 每次只能对一个备品借出申请进行延期 //// for (RaesInfo info : raesInfoList) { //// if (info.check && raid != info.raes.Rental_Apply__c) { //// ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '每次只能对一个备品借出申请进行延期')); //// return null; //// } //// } // // 打勾的明细,保存延期时间和延期理由 // List updateList = new List(); // for (RaesInfo info : raesInfoList) { // if (info.check) { // Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(Id=info.raes.Id); // raes.Request_extend_day__c = info.raes.Request_extend_day__c; // raes.Extend_request_reason__c = info.raes.Extend_request_reason__c; // raes.Extend_Status__c = '填写完毕'; // updateList.add(raes); // // 填入延长时间的,标记为延长申请的对象 // if (info.raes.Request_extend_day__c != null) { // info.isExtend = true; // } // } // } // // 更新备品借出申请的承认申请状态 //// Rental_Apply__c ra = new Rental_Apply__c(Id=raid); //// ra.ApprovalProcess_Status__c = '已填写延长申请'; // // 更新 // if (updateList.size() > 0) { // Savepoint sp = Database.setSavepoint(); // try { // update updateList; //// update ra; // Approval.ProcessSubmitRequest[] psrList = new List(); // for (Rental_Apply_Equipment_Set__c raes : updateList) { // // 开始承认流程 // Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest(); // psr.setObjectId(raes.Id); // psrList.add(psr); // } // Approval.ProcessResult[] submitResult = Approval.process(psrList); // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, '延长申请完了。')); // } catch (Exception e) { // system.debug('=====' + e.getMessage()); // ApexPages.addMessages(e); // Database.rollback(sp); // return null; // } // } // // 更新后,刷新明细行 // searchBtn(); // for (RaesInfo info : raesInfoList) { // // 刚刚延期申请的明细特殊处理 // if (info.check) { // info.check = false; // info.canChange = false; // info.status = 'Blue'; // } // } // return null; // } // 获取借出备品set一览 // 20210901 ljh SFDC-C4BBFH update start // private List getData(String txt, String con, String val, String pur, Date fd, Date td, String uname) { private List getData(String txt, String con, String val, String pur, Date fd, Date td, String uname , String fdEW, String tdEW) { // 20210901 ljh SFDC-C4BBFH update end String soql = ''; // 注释掉不再使用的数据 SWAG-B9UBDP start soql += 'select Id,Name,Demo_purpose1__c,Demo_purpose2__c,Final_reply_day__c, Return_Time_Day__c, Wei_Return_Finish__c, RetalFSetDetail_Cnt__c, ' + //'Request_extend_day__c, Extend_request_reason__c, ' + 'Extend_Status__c,'; soql += ' Rental_Apply__c,' + //'Rental_Apply__r.Foul_Points__c,Rental_Apply__r.Hospital__c, Loaner_code_text__c,'+ 'Wei_loaner_arranged__c, First_RAESD_Model_No_F__c, '; soql += ' Rental_Apply__r.Hospital__r.Hospital_Name__c,'+ 'Fixture_Set__c,'+ 'Loaner_name_F__c,Loaner_code_F__c,RAES_Status__c,SerialNumber_F__c,Rental_Apply__r.name, '; soql += ' Rental_Apply__r.Bollow_Date__c,Bollow_Date__c,'+ //'Rental_Apply__r.Person_In_Charge__c,' + 'Rental_Apply__r.Person_In_Charge__r.Name,Rental_Apply__r.Local_Borrow_Foul__c,'; soql += ' Received_Confirm__c,Received_ng_detail__c,'; soql += ' Rental_Apply__r.RecordType.Name,'; //'Return_delivery_company2__c,Return_Fedex_number2__c,Return_Distributor_method2__c,Received_confirmation_staff2__c,'+ // ''; soql += 'Rental_Apply__r.Received_Confirm_NG_Not_Return__c, '+ //' Rental_Apply__r.faraway__c, Rental_Apply__r.RequestOrderPoint_sum__c, ' + ' Rental_Apply__r.UnSign_Foul_point__c, Rental_Apply__r.Not_Create_Repair_Ordered_Date__c, Rental_Apply__r.Borrow_Date_Fouls__c, '; // 2023-02-24 zyh add start soql += ' RC_return_to_office__c, Rental_Apply__r.Cross_Region_AssignYN__c,'; // 2023-02-24 zyh add end soql += ' First_RAESD__r.DeliverySlip__c, First_RAESD__r.Return_DeliverySlip__c'; // 注释掉不再使用的数据 SWAG-B9UBDP end soql += ' from Rental_Apply_Equipment_Set__c'; soql += ' where Rental_Apply__r.OwnerId != null'; //soql += ' and Cancel_Select__c = false'; // soql += ' and Shippment_loaner_time__c != null'; // soql += ' and Lost_product_check__c != \'OK\''; soql += ' and Yi_loaner_arranged__c > 0'; soql += ' and Wei_Arrival_in_wh__c > 0'; // 欠品确认数 欠品确认未完了数,欠品确认不为OK的,因为消耗的已被未回库件数排出了,所以只看欠品中的和欠品未确认数 soql += ' and (Lost_product_cnt__c > 0 or Lost_item_check_not_finish__c > 0)'; if (!String.isBlank(uname)) { String[] vals = uname.split(' '); for (String v : vals) { soql += ' and Rental_Apply__r.Owner.Name like \'%' + String.escapeSingleQuotes(v.replaceAll('%', '\\%')) + '%\''; } } if (!isSearchAll) { //soql += ' and Shippment_loaner_time__c <> null'; //soql += ' and Received_loaner_time__c = null'; //soql += ' and Equipment_Set__r.Asset_Set_status2__c = \'2.借出中\''; //bp2 soql += ' and RAES_Status__c in (\'出库完了\',\'申请者收到确认完了\',\'申请者收货NG\',\'医院收到确认完了\',\'归还发送完了\',\'欠品中\',\'归还后CDS完了\',\'归还后检查完了\',\'回收后检测NG\',\'归还后检查完了(附属品NG)\')'; soql += ' and RAES_Status__c in (' + '\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Yi_Chu_Ku.ordinal()) + '\'' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Shen_Qing_Zhe_Yi_Shou_Huo.ordinal()) + '\'' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Shen_Qing_Zhe_Shou_Huo_NG.ordinal()) + '\'' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Yi_Yuan_Yi_Zhuang_Ji_Que_Ren.ordinal()) + '\'' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Yi_Hui_Ji.ordinal()) + '\'' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Qian_Pin_Zhong.ordinal()) + '\'' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Yi_Hui_Shou.ordinal()) + '\'' //bp2 TODO \'欠品中\' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Hui_Shou_Hou_Yi_CDS.ordinal()) + '\'' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Hui_Shou_Hou_Jian_Ce_NG.ordinal()) + '\'' //bp2 toDO \'归还后检查完了(附属品NG)\' + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Hui_Shou_Hou_Yi_Jian_Ce.ordinal()) + '\'' + ')'; } // 借出设备机身号码特别处理 if (txt == 'S:SerialNumber_F__c' && con == 'equals' && String.isNotBlank(val)) { String[] vals = val.split(','); if (vals.size() > 0) { String txt1 = txt.substring(2); // S:Name 、最初の2文字がタイプです soql += ' and ( '; for (String v : vals) { soql += txt1 + ' like \'%' + String.escapeSingleQuotes(v.replaceAll('%', '\\%')) + '%\' or '; } soql = soql.substring(0, soql.length() - 4); soql += ')'; } } else { soql += makeTextSql(txt, con, val); } if (pur != null) { soql += ' and Demo_purpose1__c = :pur '; } if (fd != null) { soql += ' and Final_reply_day__c >= :fd '; } if (td != null) { soql += ' and Final_reply_day__c <= :td '; } //20210816 ljh SFDC-C4BBFH start if(IsExceed || IsWeek){ soql += ' and Extend_Status__c != \'批准\' and Extend_Status__c != \'申请中\' '; // 超过中 if(IsExceed){ soql += ' and ((Wei_Return_Finish__c > 0 '; soql += ' and Final_reply_day__c < '+tdEW; soql += ') OR Wei_Return_Finish__c = 0)'; // Return_Time_Day__c } // 一周以内 if(IsWeek){ // Date.today().adddays(7) soql += ' and ((Wei_Return_Finish__c > 0 '; soql += ' and Final_reply_day__c >= '+fdEW; soql += ' and Final_reply_day__c < '+tdEW; soql += ') OR (Wei_Return_Finish__c = 0 '; // soql += ' and Final_reply_day__c >= Return_Time_Day__c'; soql += ' and Final_reply_day__c < '+tdEW; soql += '))'; } } //20210816 ljh SFDC-C4BBFH end if (isSoft) { soql += ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last '); } else { soql += ' order by Rental_Apply__c,Name '; } soql += ' limit ' + (Select_Limit + 1); // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, 'soql。' + tdEW+soql)); system.debug('====soql:' + soql); return Database.query(soql); } // 拼接检索条件sql文 private String makeTextSql(String txt1, String con, String val) { String soql = ''; if (String.isBlank(con)) { con = 'equals'; } // containsの場合、日報画面の病院検索を真似し、spaceで分けて、and検索 // equalsの場合、SF標準の検索を真似し、「,」で分けて、or検索 if (!String.isBlank(txt1)) { if ((con == 'contains' || con == 'notcontains') && val.contains(' ')) { String[] vals = val.split(' '); String cSql = ''; for (String v : vals) { cSql += this.makeTextSqlStr(txt1, con, v); } if (con == 'contains') { soql += cSql; } else { // notcontains cSql = cSql.replaceAll(' and ', ') and (NOT '); soql += cSql.substring(1) + ') '; } } else if ((con == 'equals' || con == 'notequals') && val.contains(',')) { String[] vals = val.split(','); if (vals.size() > 0) { String txt = txt1.substring(2); // S:Name 、最初の2文字がタイプです soql += ' and ( '; for (String v : vals) { if (con == 'equals') { soql += txt + ' = \'' + v + '\' or '; } else { // notequals soql += txt + ' <> \'' + v + '\' and '; } } soql = soql.substring(0, soql.length() - 4); soql += ')'; } } else { String cSql = this.makeTextSqlStr(txt1, con, val); if (con != 'notcontains') { soql += this.makeTextSqlStr(txt1, con, val); } else { // notcontains if (!String.isBlank(cSql)) { cSql = cSql.substring(5); // ' and ' の5文字を外す soql += ' and (NOT ' + cSql + ') '; } } } } return soql; } /** * 文字列検索文を作成 */ private String makeTextSqlStr(String txt1, String con, String val) { String soql = ''; if (!String.isBlank(txt1)) { String txt = txt1.substring(2); String colType = txt1.substring(0, 2); String tmpVal = val; // 空白の場合''にする if (String.isBlank(tmpVal)) { if (con == 'equals') { //soql += ' and ' + txt + ' = ' + tmpVal; soql += ' and ' + txt + ' = null'; } else if (con == 'notequals') { soql += ' and ' + txt + ' <> null'; } else { // 空白の場合、contains, notcontains と starts withは無視 } } else { soql += ' and ' + txt; if (con == 'equals') { if (colType == 'S:') { soql += ' = \'' + tmpVal + '\''; } else { soql += ' = ' + tmpVal + ' '; } } else if (con == 'notequals') { if (colType == 'S:') { soql += ' <> \'' + tmpVal + '\''; } else { soql += ' <> ' + tmpVal + ' '; } } else if (con == 'contains' || con == 'notcontains') { soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\''; } else if (con == 'starts with') { soql += ' like \'' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\''; } else { if (colType == 'S:') { soql += ' ' + con + '\'' + tmpVal + '\''; } else { soql += ' ' + con + ' ' + tmpVal + ' '; } } } } return soql; } @TestVisible class RaesInfo implements Comparable { public Boolean check { get; set; } // 是否选择 public Rental_Apply_Equipment_Set__c raes { get; set; } // 借出备品set一览 //public Equipment_Set__c es { get; set; } // 备品set public String esName { get; private set; } // 备品名称 public String esCode { get; private set; } // 备品型号 public String hpName { get; private set; } // 借用医院名 public String rentalPerson { get; private set; } //申请人 public Date bollowDate { get; private set; } //发货日期 public Boolean canChange { get; set; } // 是否可编辑 public String status { get; private set; } // 明细状态 public Boolean isExtend { get; private set; } // 延长申请标记 public String DetailsLine { get; private set; }//附属品明细 public String serialNumber {get; private set; }//机身编号 public String recordTypeName {get; private set; }//レコードタイプ名 public String FoulReasonStr {get; set;} //犯规理由 public RaesInfo(Boolean incheck, Rental_Apply_Equipment_Set__c inraes, Boolean incan, List raasedList) { check = incheck; raes = inraes; //es = inraes.Equipment_Set__r; esName = inraes.Loaner_name_F__c; hpName = inraes.Rental_Apply__r.Hospital__r.Hospital_Name__c; rentalPerson = inraes.Rental_Apply__r.Person_In_Charge__r.Name; bollowDate = inraes.Rental_Apply__r.Bollow_Date__c; canChange = incan; Map result = new Map(); result = getAppendage(raasedList); DetailsLine = (String)result.get('DetailsLine'); Boolean LotFlag = (Boolean)result.get('LotFlag'); if (LotFlag) { serialNumber = ' '; esCode = ' '; } else { serialNumber = inraes.SerialNumber_F__c; esCode = inraes.First_RAESD_Model_No_F__c; } recordTypeName = inraes.Rental_Apply__r.RecordType.Name; //*******************************增加生成犯规原因的功能************************************************* FoulReasonStr = ''; if (inraes.Rental_Apply__r.Not_Create_Repair_Ordered_Date__c > 0) { FoulReasonStr += '未生成RC受理日犯规 '; } if (inraes.Rental_Apply__r.UnSign_Foul_point__c > 0) { FoulReasonStr += '未签字确认犯规 '; } if (inraes.Rental_Apply__r.Received_Confirm_NG_Not_Return__c > 0) { FoulReasonStr += '现场收货NG未寄回犯规 '; } if (inraes.Rental_Apply__r.Borrow_Date_Fouls__c > 0) { FoulReasonStr += '借出日期犯规'; } if (inraes.Rental_Apply__r.Local_Borrow_Foul__c > 0) { FoulReasonStr += '未整单归还犯规'; } //*******************************增加生成犯规原因的功能************************************************* Date now = Date.today(); // OLY_OCM-610 对应 Date redDate = Date.today(); // 如果 未回寄未完了件数 == 0 说明都链上了运输单 这样的话就看最新回寄日和最新预定归还日最对比 if (inraes.Wei_Return_Finish__c == 0) { redDate = inraes.Return_Time_Day__c; } if (inraes.Extend_Status__c == '批准') { // 灰色 延長申請完了 status = 'Gray'; canChange = false; } else if (inraes.Extend_Status__c == '申请中') { // 青色 延長申請中 status = 'Blue'; } else if (inraes.Final_reply_day__c < redDate) { // 赤色 超過 status = 'Red'; } else if (inraes.Final_reply_day__c < now.adddays(7)) { // 黄色 一週間以内 status = 'Yellow'; } else { // 其他,正常颜色 status = 'Normal'; } isExtend = false; } private Map getAppendage(List raasedList) { Map resultMap = new Map(); String DetailsLine = ''; boolean LotFlag = true; if (raasedList != null) { Map DLSM = new Map(); Set AllSet = new Set(); for (Rental_Apply_Equipment_Set_Detail__c Ec : raasedList) { if (DLSM.containsKey(Ec.OwnershipMachine_No_c__c)) { integer i = DLSM.get(Ec.OwnershipMachine_No_c__c) + 1; DLSM.put(Ec.OwnershipMachine_No_c__c, i); } else { DLSM.put(Ec.OwnershipMachine_No_c__c, 1); } if (Ec.Loaner_accsessary_F__c == false) { //有主机 LotFlag = false; } //去掉主机 if (Ec.Loaner_accsessary_F__c == true) { AllSet.add(Ec.OwnershipMachine_No_c__c); } } system.debug('DLSM:::::' + DLSM); system.debug('AllSet:::::' + AllSet); for (String Ecc : AllSet) { //然后做成字符串 if (DLSM.get(Ecc) == 1) { DetailsLine = DetailsLine + Ecc + ' ; '; } else if (DLSM.get(Ecc) != 1) { DetailsLine = DetailsLine + Ecc + '*' + DLSM.get(Ecc) + ' ; '; } } if (DetailsLine.length() > 0) { DetailsLine = DetailsLine.substring(0, DetailsLine.length() - 2); } } resultMap.put('DetailsLine', DetailsLine); resultMap.put('LotFlag', LotFlag); return resultMap; } // 默认排序 Rental_Apply__c,Name public Integer compareTo(Object compareTo) { RaesInfo info = (RaesInfo)compareTo; if (check == info.check) { if (raes.Rental_Apply__c == info.raes.Rental_Apply__c) { if (raes.Name == info.raes.Name) { return 0; } if (raes.Name > info.raes.Name) { return 1; } return -1; } if (raes.Rental_Apply__c > info.raes.Rental_Apply__c) { return 1; } return -1; } if (check) { return 1; } return -1; } } public void testI() { integer i = 0; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; } }