【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“AddressGroupManager.java”一文,供大家参考学习!
package com.example.gw.addressgroup;
import com.example.businessmodel.Page;
import com.example.exception.LogicException;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import com.example.gw.unit.Unit;
import com.example.gw.unit.IUnitManager;
import com.example.util.StringUtils;
public class AddressGroupManager implements IAddressGroupManager{
private IAddressGroupDao groupDao;
private IUnitManager unitManager;
public void setGroupDao(IAddressGroupDao groupDao){
this.groupDao = groupDao;
}
public IAddressGroupDao getGroupDao(){
return groupDao;
}
public void setUnitManager(IUnitManager unitManager){
this.unitManager = unitManager;
}
public IUnitManager getUnitManager(){
return unitManager;
}
public Page getGroupList(String unitId,int start,int rowNum)throws Exception{
String where = " from AddressGroup where unitId="+unitId;
return groupDao.loadPage(where,start,rowNum);
}
public List getGroupList(String unitId){
String where = " from AddressGroup where unitId="+unitId;
return groupDao.find(where);
}
public AddressGroup getGroup(String groupId){
return (AddressGroup)groupDao.findById(AddressGroup.class,new Integer(groupId));
}
public void saveGroup(AddressGroup group)throws Exception{
String where = " from AddressGroup where groupName ='" + group.getGroupName() + "' and unitId = " + group.getUnit().getUnitId() + " and groupId <> " + group.getGroupId() + "";
if(groupDao.find(where).size()>0){
throw new LogicException("本单位已经存在" + group.getGroupName() + "这个群组");
}
groupDao.save(group);
}
public void deleteGroup(String groupId){
AddressGroup group = (AddressGroup)groupDao.findById(AddressGroup.class,new Integer(groupId));
groupDao.delete(group);
}
public List viewGroup(AddressGroup group){
String unitIdStr = group.getContent();
String[] printNum = StringUtils.split(group.getPrintNum(),",");
List unitList = unitManager.getUnitList(unitIdStr);
Iterator iter = unitList.iterator();
List retList = new ArrayList();
for(int i=0;i<printNum.length;i++){
List list = new ArrayList();
list.add(i+1+"");
list.add(((Unit)unitList.get(i)).getUnitName());
list.add(printNum[i]);
retList.add(list);
}
return retList;
}
public List getGroupUnitList(String groupId){
AddressGroup group = (AddressGroup)groupDao.findById(AddressGroup.class,new Integer(groupId));
String content = group.getContent();
return unitManager.getUnitList(content);
}
public String getGroupUnitListXml(String groupId)throws Exception{
AddressGroup group = (AddressGroup)groupDao.findById(AddressGroup.class,new Integer(groupId));
String content = group.getContent();
String printNum = group.getPrintNum();
String ret = unitManager.getUnitListXml(content).substring(0,unitManager.getUnitListXml(content).length()-7)+"<printNum>"+printNum+"</printNum></root>";
return ret ;
}
}