package neo.pcms.action;
import java.util.Map;
import neo.common.action.BaseAction;
import neo.core.common.PagingList;
import org.springframework.dao.DataIntegrityViolationException;
public class GroupAction extends BaseAction{
private PagingList groups;
private PagingList groupcounts;
private PagingList groupmember;
private Map group;
private Long groupId;
private String groupName;
private String groupDetail;
public PagingList getGroupmember() {
return groupmember;
}
public void setGroupmember(PagingList groupmember) {
this.groupmember = groupmember;
}
public String getGroupDetail() {
return groupDetail;
}
public void setGroupDetail(String groupDetail) {
this.groupDetail = groupDetail;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public Long getGroupId() {
return groupId;
}
public void setGroupId(Long groupId) {
this.groupId = groupId;
}
public Map getGroup() {
return group;
}
public void setGroup(Map group) {
this.group = group;
}
public PagingList getGroupcounts() {
return groupcounts;
}
public void setGroupcounts(PagingList groupcounts) {
this.groupcounts = groupcounts;
}
public PagingList getGroups() {
return groups;
}
public void setGroups(PagingList groups) {
this.groups = groups;
}
/*管理分组*/
public String list() throws Exception {
groups = getServMgr().getGroupService().getGroupById();
return "list";
}
/*维护分组基本信息*/
public String groupBaseManage() throws Exception {
group= getServMgr().getGroupService().getGroupInfo(groupId);
return "edit";
}
public String Update() throws Exception{
try{
getServMgr().getGroupService().updateGroupInfo(groupName,groupDetail,groupId);
addMessage("修改成功");
addRedirURL("返回","groupManage!list.action");
}
catch(DataIntegrityViolationException e){
setResult(ERROR);
addMessage("分组名称已存在");
addRedirURL("返回","@back");
}
return EXECUTE_RESULT;
}
/*删除分组*/
public String groupDelete() throws Exception{
try{
getServMgr().getGroupService().deleteGroup(groupId);
addMessage("删除成功");
addRedirURL("返回","groupManage!list.action");
}catch(DataIntegrityViolationException e){
getServMgr().getGroupService().deleteGroupFriendByGroupId(groupId);
getServMgr().getGroupService().deleteGroup(groupId);
addMessage("删除成功");
addRedirURL("返回","groupManage!list.action");
}
return EXECUTE_RESULT;
}
/*添加分组*/
public String viewAdd() throws Exception{
return "viewAdd";
}
public String groupAdd() throws Exception{
try{
getServMgr().getGroupService().addGroup(groupName,groupDetail);
addMessage("添加成功");
addRedirURL("返回","groupManage!list.action");
}catch(DataIntegrityViolationException e){
setResult(ERROR);
addMessage("该组名已存在");
addRedirURL("返回","@back");
}
return EXECUTE_RESULT;
}
/*维护组内联系人*/
private Map groupname;
public Map getGroupname() {
return groupname;
}
public void setGroupname(Map groupname) {
this.groupname = groupname;
}
public String groupMemberManage() throws Exception{
groupname = getServMgr().getGroupService().getGroupName(groupId);
groupmember = getServMgr().getGroupService().getGroupMember(groupId);
return "groupmember";
}
/*删除组内联系人*/
private Long fId;
public Long getFId() {
return fId;
}
public void setFId(Long id) {
fId = id;
}
public String deleteMember() throws Exception{
try{
getServMgr().getGroupService().deleteGroupMember(groupId,fId);
addMessage("删除成功");
addRedirURL("返回",getFullReferUrl());
}catch(DataIntegrityViolationException e){
setResult(ERROR);
addMessage("删除失败");
addRedirURL("返回", "@back");
}
return EXECUTE_RESULT;
}
/*批量删除组内联系人*/
public String deleteMulti() throws Exception{
String[] friends = (String[]) getParameters().get("friends");
for(int i=0;i<friends.length;i++)
{
log.debug(friends[i]);
}
getServMgr().getGroupService().deleteGroupMembers(friends,groupId);
addMessage("删除成功");
addRedirURL("返回",getFullReferUrl());
return EXECUTE_RESULT;
}
/*搜索将要添加的联系人*/
private PagingList search;
private String searchName;
public PagingList getSearch() {
return search;
}
public void setSearch(PagingList search) {
this.search = search;
}
public String getSearchName() {
return searchName;
}
public void setSearchName(String searchName) {
this.searchName = searchName;
}
public String search() throws Exception{
log.debug("+++++++"+groupId+"++++++++++++++++++"+searchName);
groupname = getServMgr().getGroupService().getGroupName(groupId);
search=getServMgr().getGroupService().getGroupSearchFriend(groupId,searchName);
return "search";
}
/*添加选中的联系人*/
public String addMember() throws Exception{
try{
getServMgr().getGroupService().addGroupMember(groupId,fId);
addMessage("添加成功");
addRedirURL("返回",getFullReferUrl());//getFullReferUrl()返回以标记页面,无参
}catch(DataIntegrityViolationException e){
addMessage("添加失败");
addRedirURL("返回",getFullReferUrl());
}
return EXECUTE_RESULT;
}
/*批量添加*/
public String addMulti() throws Exception{
String[] friends = (String[]) getParameters().get("friends");
for(int i=0;i<friends.length;i++)
{
log.debug(friends[i]);
}
getServMgr().getGroupService().addGroupMembers(friends,groupId);
addMessage("添加成功");
addRedirURL("返回",getFullReferUrl());
return EXECUTE_RESULT;
}
}