public without sharing class UploadOBPMController {
|
private String Id { get; set; }
|
private String errorStr { get; set; }
|
public boolean hasError { get; set; }
|
public List<OBPMInfo> OBPMInfoList { get; set; }
|
public Integer lineNo { get; set; }
|
|
public UploadOBPMController() {
|
Id = ApexPages.currentPage().getParameters().get('id');
|
}
|
|
public void init(){
|
hasError = false;
|
OBPMInfoList = new List<OBPMInfo>();
|
|
List<Campaign> camList = [select id, Name, Shared_User__c from Campaign where id = :Id];
|
if (camList.size() == 0) {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '学会不存在。'));
|
hasError = true;
|
return;
|
}
|
Integer line = 0;
|
for (Integer i = 0; i < 5; i++) {
|
line += 1;
|
OBPMInfo temp = new OBPMInfo(line, new Campaign());
|
OBPMInfoList.add(temp);
|
}
|
}
|
|
public List<SelectOption> getItems() {
|
List<SelectOption> options = new List<SelectOption>();
|
options.add(new SelectOption('','--无--'));
|
options.add(new SelectOption('共同编辑人','共同编辑人'));
|
options.add(new SelectOption('抄送人','抄送人'));
|
return options;
|
}
|
|
public PageReference addLine() {
|
Integer nowLine = (OBPMInfoList == null ? 0 : OBPMInfoList.size());
|
OBPMInfo newopi = new OBPMInfo(nowLine + 1, new Campaign());
|
List<OBPMInfo> tempList = new List<OBPMInfo>();
|
for (OBPMInfo ob : OBPMInfoList) {
|
tempList.add(ob);
|
}
|
tempList.add(newopi);
|
OBPMInfoList = tempList.clone();
|
return null;
|
}
|
|
public PageReference deleteLine() {
|
Integer rownum = 0;
|
List<OBPMInfo> tempList = new List<OBPMInfo>();
|
for (OBPMInfo ob : OBPMInfoList) {
|
if (ob.line != lineNo) {
|
rownum += 1;
|
OBPMInfo tmp = new OBPMInfo(rownum, ob.cam, ob.Role);
|
tempList.add(tmp);
|
}
|
}
|
OBPMInfoList = tempList.clone();
|
return null;
|
}
|
|
public PageReference uploadOBPM() {
|
List<String> userIdList = new List<String>();
|
Map<String,String> userMap = new Map<String,String>();
|
List<Campaign> camList = new List<Campaign>();
|
Campaign cam = [select id, Name, Shared_User__c, Shared_Editing__c, Carbon_Copy__c from Campaign where id = :Id];
|
for(OBPMInfo ob : OBPMInfoList){
|
if(String.isNotBlank(ob.cam.Shared_User__c) && (ob.Role == '共同编辑人' || ob.Role =='抄送人')){
|
userIdList.add(ob.cam.Shared_User__c);
|
}
|
}
|
if(userIdList.size() > 0){
|
String SharedEditing;
|
String CarbonCopy;
|
List<User> userList = [select id, Employee_No__c from User where id = :userIdList];
|
for(User user : userList){
|
userMap.put(user.id, user.Employee_No__c);
|
}
|
for(OBPMInfo ob : OBPMInfoList){
|
if(String.isNotBlank(ob.cam.Shared_User__c)){
|
if(userMap.containsKey(ob.cam.Shared_User__c)){
|
if(ob.Role == '共同编辑人'){
|
SharedEditing += userMap.get(ob.cam.Shared_User__c) + ',';
|
} else if(ob.Role == '抄送人'){
|
CarbonCopy += userMap.get(ob.cam.Shared_User__c) + ',';
|
}
|
}
|
}
|
}
|
//截取掉null和最后的逗号
|
SharedEditing = SharedEditing.substring(4, SharedEditing.lastIndexOf(','));
|
CarbonCopy = CarbonCopy.substring(4, CarbonCopy.lastIndexOf(','));
|
cam.Shared_Editing__c = SharedEditing;
|
cam.Carbon_Copy__c = CarbonCopy;
|
camList.add(cam);
|
}
|
errorStr = '';
|
Savepoint sp = Database.setSavepoint();
|
try {
|
if(camList.size() > 0){
|
update camList;
|
}
|
} catch (System.Exception e) {
|
Database.rollback(sp);
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
|
errorStr = e.getMessage();
|
hasError = true;
|
return null;
|
}
|
return null;
|
}
|
|
public class OBPMInfo {
|
public Integer line { get; set; }
|
public Campaign cam { get; set; }
|
public String Role { get; set; }
|
public OBPMInfo(Integer lineInfo, Campaign camInfo){
|
line = lineInfo;
|
cam = camInfo;
|
Role = '';
|
}
|
public OBPMInfo(Integer lineInfo, Campaign camInfo, String roleInfo){
|
line = lineInfo;
|
cam = camInfo;
|
Role = roleInfo;
|
}
|
}
|
}
|