public with sharing class RentalApplyJumpController { /*--------- private ---------*/ public Id objId {get; set;} // 申请单ID private String raesIds {get; set;} // 被选中的一览记录Id public String saveStatus {get; set;} // 插队结果: 'ok'--成功 /*--------- public(画面表示用) ---------*/ public List infoList {get; set;} // 符合插队条件的被选中的一览记录 public Id RaId {get; private set;} // 申请单Id public Integer infoListSize { get { return infoList == null ? 0 : infoList.size(); } } public String errorMessage; List raesdList; public RentalApplyJumpController() { this.objId = ApexPages.currentPage().getParameters().get('objId'); this.raesIds = ApexPages.currentPage().getParameters().get('raesIds'); RaId = this.objId; raesdList = new List(); } public void init() { infoList = new List(); try{ if (String.isBlank(this.objId)) { throw new ControllerUtil.myException('请设置备品借出申请的Id'); } if (String.isBlank(this.raesIds)) { throw new ControllerUtil.myException('请设置备品借出申请一览的Id'); } check(); for(Rental_Apply_Equipment_Set_Detail__c rd:raesdList){ LineInfo lf = new LineInfo(rd); infoList.add(lf); } } catch (ControllerUtil.myException me) { System.debug('myException caught when init: ' + me.getMessage()); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, me.getMessage())); errorMessage = me.getStackTraceString(); return; } catch (Exception e) { System.debug('Exception caught when init: ' + e.getStackTraceString()); ApexPages.addMessages(e); errorMessage = e.getStackTraceString(); return; } } public PageReference saveJump() { check(); List updList = new List(); // 明细行check Integer cntSelect = 0; Boolean hasError = false; for (LineInfo line : infoList) { if (line.isSelect == true) { if (String.isBlank(line.raesd.jumpReason__c)) { line.raesd.jumpReason__c.addError('请输入插队原因'); hasError = true; } cntSelect += 1; } } if (cntSelect == 0) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '未选择插队的明细。')); hasError = true; } if (hasError == true) { return null; } // 保存逻辑 for (LineInfo line : infoList) { if (line.isSelect == true) { Rental_Apply_Equipment_Set_Detail__c upd = new Rental_Apply_Equipment_Set_Detail__c(); upd = line.raesd; // upd.Allow_Adjust_Queue_Flag__c = line.raesd.Allow_Adjust_Queue_Flag__c; upd.Allow_Adjust_Queue_Flag__c = true; upd.jumpReason__c = line.raesd.jumpReason__c; updList.add(upd); } } FixtureUtil.withoutUpdate(updList); saveStatus = 'ok'; ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '保存完了。')); // 发送邮件 return null; } public void check(){ // 判断是否存在状态和Id和父申请单都符合的选中一览记录 String[] ids = raesIds.split(','); // 分单条件之一览状态--'待分配', '排队中', // '暂定分配' Set statusRaesSet = new Set{FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Dai_Fen_Pei.ordinal()), FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Pai_Dui_Zhong.ordinal()) // ,FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Zan_Ding_Fen_Pei.ordinal()) }; raesdList = [ SELECT Id, Name,RAESD_Status__c,Rental_Apply__c,Fixture_Model_No__c,Rental_Apply_Equipment_Set__c, Allow_Adjust_Queue_Flag__c,jumpReason__c FROM Rental_Apply_Equipment_Set_Detail__c WHERE Is_Body__c = true AND Rental_Apply_Equipment_Set__c in :ids AND Rental_Apply__c = :this.objId AND RAESD_Status__c in :statusRaesSet]; if(raesdList.size() != ids.size()) { throw new ControllerUtil.myException('已选一览状态不符合插队条件,请选择明细状态都是 待分配与排队中的一览'); } } class LineInfo { // 选择 public boolean isSelect { get; set; } // 借出备品set一览 明细 public Rental_Apply_Equipment_Set_Detail__c raesd { get; set; } public LineInfo(Rental_Apply_Equipment_Set_Detail__c r) { isSelect = false; raesd = r; } } }