public class QueuePageByAssetIdController extends CreateRelationListPagingCtrlBase{ private Id asId; private String wher; // and 4つ条件 private Map queueConmentMap; //public Asset aset {get;private set;} public Rental_Apply_Equipment_Set_Detail__c raesd {get;private set;} public String modelNo {get;private set;} public Boolean isNotShow {get;private set;} public Integer inptNum {get; set;} public Integer inptNumStr {get; set;} public Boolean inputUpDownFlag {get; set;} public override Boolean getIsNeedRunSearch() { return false; } /* 選択されたデータ取得用Soql Fromから*/ public override String getSelectedDataSql() { // オブジェクトAPI名 selectedDataSql = ' From Rental_Apply_Equipment_Set_Detail__c'; selectedDataSql += ' where Queue_Number__c > 0 AND Fixture_Model_No_text__c = \'' + modelNo + '\''; selectedDataSql += ' AND Cancel_Select__c = false ' + wher; selectedDataSql += ' order by Queue_Number__c ASC nulls last'; // 20220107 ljh update start /*Profile profileObj = [SELECT Id, Name FROM Profile WHERE Id =: UserInfo.getProfileId() LIMIT 1]; // 只有系统管理员,页面上 排队No,排队时间,负责人 字段是显示可编辑状态 if (profileObj == null || (profileObj != null && !profileObj.Name.contains('系统管理员'))) { myComponentController.columnRightRW.put('Queue_Number__c', 'r'); myComponentController.columnRightRW.put('Queue_Day__c', 'r'); myComponentController.columnRightRW.put('Queue_User__c', 'r'); }*/ // 20220107 ljh update end myComponentController.columnRightRW.put('Allow_Adjust_Queue_Flag__c', 'r'); myComponentController.columnRightRW.put('jumpReason__c', 'r'); return selectedDataSql; } public override String getOriginObjName() { // オブジェクトAPI名 originObjName = 'Rental_Apply_Equipment_Set_Detail__c'; return originObjName; } public override String getOriginObjColumns() { // 項目セット // 20211104 ljh 排队 start // originObjColumns = 'Id, Asset__c'; originObjColumns = 'Id'; // 20211104 ljh 排队 end return originObjColumns; } public override Integer getSearchNumMax() { //各ページに制御あれば、最大件数を指定する searchNumMax = Integer.valueOf(Label.Product_Select_Limit); return searchNumMax; } public override String getObjName() { // オブジェクトAPI名 objName = 'Rental_Apply_Equipment_Set_Detail__c'; return objName; } // ページコントローラに検索処理は、WhereSoql作成のみ、パラメータとして、コンポーネントに渡される public override String getSqlWhereStr() { sqlWhereStr = ''; return sqlWhereStr; } public override String getColumnRightFieldSetName() { // 右の項目セット columnRightFieldSetName = 'QueueByAssetId'; return columnRightFieldSetName; } public override String getColumnLeftFieldSetName() { // 左の項目セット columnLeftFieldSetName = ''; return columnLeftFieldSetName; } public override List getColumnFieldList() { // strColumus 里加 field return new String[]{'Is_Body_F__c', 'Rental_Apply__c'}; } // 画面里直接可以输入的項目 List public override List getWritableColumnFieldList() { return new List{'Queue_Conment__c'}; } public override String getRecordTypeId() { //ページレイアウトを収得するのレコードタイプ recordTypeId = ''; return recordTypeId; } // getObjName 连 getOriginObjName 的 FK public override String getFKColumnField() { return null; } //public override public override void setViewList(List queryList) { queueConmentMap = new Map(); viewList = new List(); for (Integer i = 0; i < selectedData.size(); i++) { Rental_Apply_Equipment_Set_Detail__c raesd = (Rental_Apply_Equipment_Set_Detail__c) selectedData[i]; if (raesd.Is_Body_F__c == false) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'借出备品配套一览明细:' + raesd.Id + ' 不是主体不能排队')); } WrapperInfo w = new WrapperInfo(raesd, myComponentController); w.orderNo = raesd.Queue_Number__c.intValue(); w.lineNo = i; if (w.orderNo != i + 1) { w.orderNo = w.lineno + 1; w.changeFlg = '1'; } viewList.add(w); queueConmentMap.put(raesd.Id, raesd.Queue_Conment__c); } } public void saveQueue(){ Savepoint sp = Database.setSavepoint(); Boolean isCheckedFlag = false; try { for (WrapperInfo w : viewList) { Rental_Apply_Equipment_Set_Detail__c rae = (Rental_Apply_Equipment_Set_Detail__c) w.sobj; if (w.check) { isCheckedFlag = true; if (rae.Is_Body_F__c == false) { inptNumStr = null; throw new ControllerUtil.myException('借出备品配套一览明细:' + rae.Id + ' 不是主体不能排队'); } // 没有调整队列,只更改排队备注的情况 if (!inputUpDownFlag && (inptNum == 0 || inptNum == null)) { List raesdObjList = new List(); Rental_Apply_Equipment_Set_Detail__c raesdObj = new Rental_Apply_Equipment_Set_Detail__c(); raesdObj.Id = rae.Id; raesdObj.Queue_Conment__c = rae.Queue_Conment__c; raesdObj.Queue_User__c = UserInfo.getUserId(); raesdObjList.add(raesdObj); FixtureUtil.withoutUpdate(raesdObjList); } else { // 调整队列的情况 if (!rae.Allow_Adjust_Queue_Flag__c) { inptNumStr = null; throw new ControllerUtil.myException('备品总窗口未申请插队,无法调整顺序,请确认。'); } if (inputUpDownFlag && inptNum == 0) { throw new ControllerUtil.myException('错误的【指定排队NO.】:0'); } else { Rental_Apply_Equipment_Set_Detail__c raesd = [ SELECT Id, Allow_Adjust_Queue_Flag__c, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c FROM Rental_Apply_Equipment_Set_Detail__c WHERE Id =: rae.Id AND Is_Body__c = true AND Cancel_Select__c = false]; if (raesd == null) { inptNumStr = null; throw new ControllerUtil.myException('调整的一览明细不存在。'); } if (inputUpDownFlag && raesd.Queue_Number__c <= inptNum) { throw new ControllerUtil.myException('请使用【指定排队NO.】来向上调整排队No。'); } saveQueue(rae, inptNum, inputUpDownFlag, false); } } } } inptNumStr = null; inputUpDownFlag = false; inptNum = null; myComponentController.getSelectedDataInfo(); getSqlWhereStr(); myComponentController.searchAndPaging(); if (isCheckedFlag) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'保存成功')); } else { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'请勾选需要操作的数据')); } } catch (Exception e) { Database.rollback(sp); inputUpDownFlag = false; inptNum = null; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getmessage())); } } public QueuePageByAssetIdController(){ // 20211104 ljh 排队 start // this.asId = ApexPages.currentPage().getParameters().get('asId'); // this.parentId = asId; this.parentId = ApexPages.currentPage().getParameters().get('parentId'); if (ApexPages.currentPage().getParameters().get('isNotShow') == 'true') { this.isNotShow = true; } else { this.isNotShow = false; } // 20211104 ljh 排队 end } public void init() { isNeedSearchFirst = false; getSqlWhereStr(); this.wher = ''; List raesdObjs = [ SELECT Id, Rental_Apply_Equipment_Set__c, Asset__c,Salesdepartment_before__c, Product_category_text__c,Equipment_Type_text__c, Internal_asset_location_before__c,Fixture_Model_No__c,Fixture_Model_No_F__c FROM Rental_Apply_Equipment_Set_Detail__c WHERE Rental_Apply_Equipment_Set__c = :parentId and Is_Body__c = true and Cancel_Select__c = false]; if (raesdObjs.isEmpty()) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'备品一览明细不存在。')); return; } raesd = raesdObjs[0]; this.modelNo = raesd.Fixture_Model_No__c; if (String.isNotBlank(raesd.Salesdepartment_before__c)) { wher += ' AND Salesdepartment_before__c = \'' + raesd.Salesdepartment_before__c + '\''; } if (String.isNotBlank(raesd.Product_category_text__c)) { wher += ' AND Product_category_text__c = \'' + raesd.Product_category_text__c + '\''; } if (String.isNotBlank(raesd.Equipment_Type_text__c)) { wher += ' AND Equipment_Type_text__c = \'' + raesd.Equipment_Type_text__c + '\''; } if (String.isNotBlank(raesd.Internal_asset_location_before__c)) { wher += ' AND Internal_asset_location_before__c = \'' + raesd.Internal_asset_location_before__c + '\''; } } /** * 申请单置顶 * */ public void upRentalApply() { Savepoint sp = Database.setSavepoint(); Boolean isCheckedFlag = false; try { for (WrapperInfo w : viewList) { Rental_Apply_Equipment_Set_Detail__c rae = (Rental_Apply_Equipment_Set_Detail__c) w.sobj; if (w.check) { isCheckedFlag = true; if (!rae.Allow_Adjust_Queue_Flag__c) { inptNumStr = null; throw new ControllerUtil.myException('备品总窗口未申请插队,无法调整顺序,请确认。'); } // 只置顶申请单中已排队,且非暂定分配的一览明细 List raesdObjs = [ SELECT Id, Allow_Adjust_Queue_Flag__c, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c, Name FROM Rental_Apply_Equipment_Set_Detail__c WHERE Rental_Apply__c =: rae.Rental_Apply__c AND Is_Body__c = true AND Cancel_Select__c = false AND Queue_Number__c > 0]; // 校验申请单中已排队的其余一览明细的状态 for(Rental_Apply_Equipment_Set_Detail__c raesd : raesdObjs){ if (!raesd.Allow_Adjust_Queue_Flag__c) { inptNumStr = null; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'一览明细:' + raesd.Name + ' 型号:' + raesd.Fixture_Model_No__c + ' 备品总窗口未申请插队,无法调整顺序,请确认。')); return; } //申请单置顶 saveQueue(raesd, 1, true, false); } } } inptNumStr = null; inputUpDownFlag = false; inptNum = null; myComponentController.getSelectedDataInfo(); getSqlWhereStr(); myComponentController.searchAndPaging(); if (isCheckedFlag) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'申请单置顶成功')); } else { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'请勾选需要操作的数据')); } } catch (Exception e) { Database.rollback(sp); inputUpDownFlag = false; inptNum = null; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getmessage())); } } /** * 调整排队的队列顺序 * @param raesdObj 需要调整的对象 * @param num 调整到的排队No * @param upDownFlag 向上或者向下调整标识 true:向上; false:向下 * @param isSkip 是否跳过调整顺序校验 true:跳过校验; false:校验 */ public void saveQueue(Rental_Apply_Equipment_Set_Detail__c raesdObj, Integer num, Boolean upDownFlag, Boolean isSkip) { List raes = new List(); Rental_Apply_Equipment_Set_Detail__c raesd = [ SELECT Id, Allow_Adjust_Queue_Flag__c, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c FROM Rental_Apply_Equipment_Set_Detail__c WHERE Id =: raesdObj.Id AND Is_Body__c = true AND Cancel_Select__c = false FOR UPDATE]; if (raesd == null) { inptNumStr = null; throw new ControllerUtil.myException('调整的一览明细不存在。'); } if (!raesd.Allow_Adjust_Queue_Flag__c && !isSkip) { inptNumStr = null; throw new ControllerUtil.myException('一览明细:' + raesd.Name + ' 型号:' + raesd.Fixture_Model_No__c + ' 备品总窗口未申请插队,无法调整顺序,请确认。'); } if (upDownFlag && raesd.Queue_Number__c == num) { return; } List raesdList = [ SELECT Id, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c FROM Rental_Apply_Equipment_Set_Detail__c WHERE Queue_Number__c > 0 AND Cancel_Select__c = false AND ExternalKey__c =: raesd.ExternalKey__c ORDER BY Queue_Number__c ASC nulls last]; // 先调整队列顺序,后再调整序列顺序 // upDownFlag true:向上调整、置顶 false:置底 // 需要按照页面段的检索条件,取出队列一览,来做调整队列时的比较 Integer orderNo = 1; for (Rental_Apply_Equipment_Set_Detail__c rae : raesdList) { // 向上调整、置顶 if (upDownFlag) { if (orderNo >= num && orderNo < raesd.Queue_Number__c) { rae.Queue_Number__c = orderNo + 1; rae.Queue_User__c = UserInfo.getUserId(); raes.add(rae); } } else { // 置底 if (orderNo > raesd.Queue_Number__c) { rae.Queue_Number__c = orderNo - 1; rae.Queue_User__c = UserInfo.getUserId(); raes.add(rae); } } orderNo++; } if (upDownFlag) { // 置顶或者向上,需要传调整Num raesdObj.Queue_Number__c = num; } else { // 置底直接用队列的size raesdObj.Queue_Number__c = raesdList.size(); } // 插队Flag raesdObj.Asset__c = null; raesdObj.IsAdjust__c = true; raesdObj.Queue_User__c = UserInfo.getUserId(); raes.add(raesdObj); // 更新队列信息 FixtureUtil.withoutUpdate(raes); // 更新序列信息,先确认是单一序列还是混合序列,混合序列顺序不做调整 List rasList = [ SELECT Id, Series_No__c, ExternalKey__c, Apply_Set_Detail_ExternalKey__c FROM Rental_Apply_Sequence__c WHERE Apply_Set_Detail__c =: raesd.Id AND Invalid_Flag__c = false]; Map externalKeyMap = new Map(); for (Rental_Apply_Sequence__c ras : rasList) { externalKeyMap.put(ras.ExternalKey__c, 1); } // 先检索出混合序列,从更新序列中排除 List rasList1 = [ SELECT ExternalKey__c FROM Rental_Apply_Sequence__c WHERE Invalid_Flag__c = false AND ExternalKey__c IN: externalKeyMap.keySet() AND Apply_Set_Detail_ExternalKey__c !=: raesd.ExternalKey__c ORDER BY ExternalKey__c]; for (Rental_Apply_Sequence__c ras : rasList1) { if (externalKeyMap.containsKey(ras.ExternalKey__c)) { externalKeyMap.remove(ras.ExternalKey__c); } } // 检索出单一序列,更新单一序列 List rasList2 = [ SELECT Id, Series_No__c, Apply_Set_Detail__r.Queue_Number__c FROM Rental_Apply_Sequence__c WHERE Invalid_Flag__c = false AND ExternalKey__c IN: externalKeyMap.keySet() AND Series_Unequal_Queue_Flag__c = true ORDER BY ExternalKey__c]; for (Rental_Apply_Sequence__c ras : rasList2) { ras.Series_No__c = ras.Apply_Set_Detail__r.Queue_Number__c; } // 更新单一序列信息 FixtureUtil.withoutUpdate(rasList2); } /** * 调整队列 + 申请单置顶,并没有比以前改进多少,还难维护,所以注释掉 * */ /*public void saveQueue(List raesdObjs, Integer num, Boolean upDownFlag) { Map raesdMap = new Map([ SELECT Id, Allow_Adjust_Queue_Flag__c, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c, Rental_Apply__c FROM Rental_Apply_Equipment_Set_Detail__c WHERE Id IN: raesdObjs AND Is_Body__c = true AND Cancel_Select__c = false ORDER BY ExternalKey__c, Queue_Number__c ASC nulls last]); String rentalApplyId = null; // 同一申请单中相同型号的设备排同样队列的情况下,需要按照ExternalKey来Map Map> externalMap = new Map>(); for (Rental_Apply_Equipment_Set_Detail__c raesdObj : raesdObjs) { if (!raesdMap.containsKey(raesdObj.Id)) { throw new ControllerUtil.myException('调整的一览明细不存在。'); } else { Rental_Apply_Equipment_Set_Detail__c raesdTemp = raesdMap.get(raesdObj.Id); rentalApplyId = raesdTemp.Rental_Apply__c; if (!raesdTemp.Allow_Adjust_Queue_Flag__c) { throw new ControllerUtil.myException('备品总窗口未申请插队,无法调整顺序,请确认。'); } if (upDownFlag && raesdTemp.Queue_Number__c <= num) { throw new ControllerUtil.myException('请使用【指定排队NO.】来向上调整排队No。'); } if (!externalMap.containskey(raesdTemp.ExternalKey__c)) { List tempList = new List(); tempList.add(raesdTemp); externalMap.put(raesdTemp.ExternalKey__c, tempList); } else { List tempList = externalMap.get(raesdTemp.ExternalKey__c); tempList.add(raesdTemp); externalMap.put(raesdTemp.ExternalKey__c, tempList); } } } List raesUpdList = new List(); if (!externalMap.keySet().isEmpty()) { List raesdList = [ SELECT Id, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c, Rental_Apply__c FROM Rental_Apply_Equipment_Set_Detail__c WHERE Queue_Number__c > 0 AND Cancel_Select__c = false AND ExternalKey__c IN: externalMap.keySet() ORDER BY ExternalKey__c, Queue_Number__c ASC nulls last]; // 先调整队列顺序,后再调整序列顺序 // upDownFlag true:向上调整、置顶 false:置底 // 需要按照页面段的检索条件,取出队列一览,来做调整队列时的比较 if (raesdObjs.size() == 1) { Rental_Apply_Equipment_Set_Detail__c raesd = raesdMap.get(raesdObjs[0].Id); // 区分申请单置顶 和 别的操作 Integer orderNo = 1; for (Rental_Apply_Equipment_Set_Detail__c rae : raesdList) { // 向上调整、置顶 if (upDownFlag) { if (orderNo >= num && orderNo < raesd.Queue_Number__c) { rae.Queue_Number__c = orderNo + 1; rae.Queue_User__c = UserInfo.getUserId(); raesUpdList.add(rae); } } else { // 置底 if (orderNo > raesd.Queue_Number__c) { rae.Queue_Number__c = orderNo - 1; rae.Queue_User__c = UserInfo.getUserId(); raesUpdList.add(rae); } } orderNo++; } if (upDownFlag) { // 置顶或者向上,需要传调整Num raesdObjs[0].Queue_Number__c = num; } else { // 置底直接用队列的size raesdObjs[0].Queue_Number__c = raesdList.size(); } // 插队Flag raesdObjs[0].IsAdjust__c = true; raesdObjs[0].Queue_User__c = UserInfo.getUserId(); raesUpdList.add(raesdObjs[0]); } else { // 申请单置顶 Integer orderNo = 1; Integer endNo = 0; String externalKeyTemp = null; for (Rental_Apply_Equipment_Set_Detail__c rae : raesdList) { if (rae.ExternalKey__c != externalKeyTemp) { externalKeyTemp = rae.ExternalKey__c; orderNo = externalMap.get(externalKeyTemp).size(); endNo = (Integer)externalMap.get(externalKeyTemp)[orderNo-1].Queue_Number__c; } if (rae.Rental_Apply__c != rentalApplyId) { // 向上调整、置顶 if (upDownFlag) { if (rae.Queue_Number__c >= num && rae.Queue_Number__c < endNo) { rae.Queue_Number__c = orderNo + 1; rae.Queue_User__c = UserInfo.getUserId(); raesUpdList.add(rae); } } } orderNo++; } if (upDownFlag) { for (String external : externalMap.keySet()) { List tempList = new List(); tempList = externalMap.get(external); orderNo = 1; for (Rental_Apply_Equipment_Set_Detail__c raesTemp : tempList) { // 置顶 raesTemp.Queue_Number__c = orderNo; // 插队Flag raesTemp.IsAdjust__c = true; raesTemp.Queue_User__c = UserInfo.getUserId(); raesUpdList.add(raesTemp); orderNo++; } } } } } if (!raesUpdList.isEmpty()) { if(raesUpdList.size() > 9000){ throw new ControllerUtil.myException('当前数据量过大,请到进行单条数据操作'); } // 更新队列信息 FixtureUtil.withoutUpdate(raesUpdList); } // 更新序列信息,先确认是单一序列还是混合序列,混合序列顺序不做调整 List rasList = [ SELECT Id, Series_No__c, ExternalKey__c, Apply_Set_Detail_ExternalKey__c FROM Rental_Apply_Sequence__c WHERE Apply_Set_Detail__c IN: raesdObjs AND Invalid_Flag__c = false]; Map externalKeyMap = new Map(); for (Rental_Apply_Sequence__c ras : rasList) { externalKeyMap.put(ras.ExternalKey__c, 1); } // 先检索出混合序列,从更新序列中排除 List rasList1 = [ SELECT ExternalKey__c FROM Rental_Apply_Sequence__c WHERE Invalid_Flag__c = false AND ExternalKey__c IN: externalKeyMap.keySet() AND Apply_Set_Detail_ExternalKey__c !=: raesd.ExternalKey__c ORDER BY ExternalKey__c]; for (Rental_Apply_Sequence__c ras : rasList1) { if (externalKeyMap.containsKey(ras.ExternalKey__c)) { externalKeyMap.remove(ras.ExternalKey__c); } } // 检索出单一序列,更新单一序列 List rasList2 = [ SELECT Id, Series_No__c, Apply_Set_Detail__r.Queue_Number__c FROM Rental_Apply_Sequence__c WHERE Invalid_Flag__c = false AND ExternalKey__c IN: externalKeyMap.keySet() AND Series_Unequal_Queue_Flag__c = true ORDER BY ExternalKey__c]; for (Rental_Apply_Sequence__c ras : rasList2) { ras.Series_No__c = ras.Apply_Set_Detail__r.Queue_Number__c; } if (!rasList2.isEmpty()) { if(raesUpdList.size() + rasList2.size() > 9000){ throw new ControllerUtil.myException('当前数据量过大,请到进行单条数据操作'); } // 更新单一序列信息 FixtureUtil.withoutUpdate(rasList2); } }*/ }