public int DeleteDept(int id, string accessToken) { int rows = 0; GROUP_INFO groupInfo = _groupRepo.Get(id); if (groupInfo != null) { int childrenCount = _groupRepo.GetCountByParentID(id); if (childrenCount > 0) { rows = -1; //如果有子部门,不能删除 } int empCount = _empRepo.GetCountByGroupID(id); if (empCount > 0) { rows = -2; //组织结构下有员工,不能删除 } DeptResponse response = WXQYClientServiceApi.Create().DeleteDept(accessToken, groupInfo.WX_GROUP_ID); if (response != null && response.ErrorCode == 0) { rows = _groupRepo.Delete(id); if (groupInfo.TYPE == 3) { MDSearch storeInfo = _storeRepo.GetByGroupId(id); if (storeInfo != null) { _storeRepo.Delete(storeInfo.ID); } } } } return(rows); }
public void InitDepartments(string accessToken) { //select a.ID,a.NAME,a.PARENT_ID,a.WX_GROUP_ID,a.wx_parent_id, //b.ID,b.NAME, b.WX_GROUP_ID,b.wx_parent_id, //'update GROUP_INFO set PARENT_ID = ' + str(b.ID) + ' where ID =' + str(a.ID) //from GROUP_INFO a //left //join GROUP_INFO b on a.wx_parent_id = b.WX_GROUP_ID //where b.id is not null //select *, //'update MDSearch set group_id='+STR(g.ID) +' where id = '+str(m.ID), //'update group_info set code =''' + m.Code+''' where id= ' +STR(g.id) //from GROUP_INFO g //inner join MDSearch m on m.Name = g.NAME int rootId = AppConfig.QYDeptRootID; DeptListResponse response = WXQYClientServiceApi.Create().QueryDept(accessToken, rootId); if (response != null && response.Departments != null) { List <GROUP_INFO> groupList = new List <GROUP_INFO>(); List <Department> children = response.Departments.FindAll(m => m.ID != rootId); foreach (var item in children) { GROUP_INFO g = new GROUP_INFO(); g.NAME = item.Name; g.CODE = ""; g.PARENT_ID = 0; if (item.ParentID == rootId) { g.TYPE = 1; } else { var cc = children.FindAll(m => m.ParentID == item.ID); if (cc.Count > 0) { g.TYPE = 2; } else { g.TYPE = 3; } } g.WX_GROUP_ID = item.ID; g.WX_PARENT_ID = item.ParentID; g.WX_ORDER = item.Order; g.CREATE_TIME = DateTime.Now; g.CREATE_USER = "******"; groupList.Add(g); } _storeRepo.BatchInsert(groupList); } }
private void GetParentDeptNames(List <GROUP_INFO> groupList, int deptId, ref string fullDepNames) { GROUP_INFO g = groupList.Find(m => m.ID == deptId); if (g != null) { fullDepNames = ("/" + g.NAME) + fullDepNames; GetParentDeptNames(groupList, g.PARENT_ID, ref fullDepNames); } }
/// <summary> ///新建或更改角色信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { if (checkisok() == true) { if (db.GROUP_INFOs.Count(q => q.GI_NAME == txtRoleName.Text) == 0) //新建 { GROUP_INFO gi = new GROUP_INFO { GI_NAME = txtRoleName.Text.Trim() }; db.GROUP_INFOs.InsertOnSubmit(gi); db.SubmitChanges(); //配置权限 foreach (var i in lbxYes.Items) { GROUP_AUTHORITY ga = new GROUP_AUTHORITY { GA_GIID = gi.GI_ID, GA_ALNAME = i.ToString() }; db.GROUP_AUTHORITies.InsertOnSubmit(ga); } db.SubmitChanges(); MessageBox.Show("添加成功!"); } else //修改 { var gi = db.GROUP_INFOs.First(q => q.GI_NAME == txtRoleName.Text); //权限更改 var deleteOrderDetails = db.GROUP_AUTHORITies.Where(p => p.GA_GIID == gi.GI_ID); foreach (var detail in deleteOrderDetails) { db.GROUP_AUTHORITies.DeleteOnSubmit(detail); } //db.SubmitChanges(); foreach (var i in lbxYes.Items) { GROUP_AUTHORITY ga = new GROUP_AUTHORITY { GA_GIID = gi.GI_ID, GA_ALNAME = i.ToString() }; db.GROUP_AUTHORITies.InsertOnSubmit(ga); } db.SubmitChanges(); MessageBox.Show("修改成功!"); } loadRoles(); } }
private bool Where(GROUP_INFO n, string groupid) { bool iswhere = false; foreach (var item in groupid.Split(',')) { if (string.IsNullOrEmpty(item)) { continue; } if (n.PARENT_ID == int.Parse(item)) { iswhere = true; continue; } } return(iswhere); }
/// <summary> /// 修改组织架构 /// </summary> /// <param name="accessToken"></param> /// <param name="deptId"></param> /// <param name="parentId"></param> /// <returns></returns> public int UpdateDeptOrg(string accessToken, int deptId, int parentId, ref string errMsg) { int rows = 0, rootId = AppConfig.QYDeptRootID; GROUP_INFO existGroupInfo = _groupRepo.Get(deptId); if (existGroupInfo != null) { int wxParentId = 0; if (parentId == 0) { wxParentId = rootId; } else { GROUP_INFO parentInfo = _groupRepo.Get(parentId); if (parentInfo != null) { wxParentId = parentInfo.WX_GROUP_ID; } } DeptResponse response = WXQYClientServiceApi.Create().UpdateDept(accessToken, existGroupInfo.WX_GROUP_ID, existGroupInfo.NAME, wxParentId, existGroupInfo.WX_ORDER.Value); if (response != null && response.ErrorCode == 0) { GROUP_INFO groupInfo = new GROUP_INFO(); groupInfo.ID = deptId; groupInfo.PARENT_ID = parentId; groupInfo.WX_PARENT_ID = wxParentId; groupInfo.LAST_MODIFY_TIME = DateTime.Now; groupInfo.LAST_MODIFY_USER = "******"; groupInfo.FullUpdate = false; rows = (int)_groupRepo.Update(groupInfo); } else { errMsg = response.ErrorMessage; } } return(rows); }
public DeptInfo GetDept(int id, int type) { DeptInfo deptInfo = null; GROUP_INFO groupInfo = _groupRepo.Get(id); if (groupInfo != null) { deptInfo = new DeptInfo(); deptInfo.ID = groupInfo.ID; deptInfo.DeptName = groupInfo.NAME; deptInfo.DeptCode = groupInfo.CODE; deptInfo.Type = groupInfo.TYPE; deptInfo.MagentoGroupID = groupInfo.MAGENTO_GROUP_ID; deptInfo.Order = groupInfo.WX_ORDER.HasValue ? groupInfo.WX_ORDER.Value : 0; deptInfo.ParentID = groupInfo.PARENT_ID; deptInfo.WXGroupID = groupInfo.WX_GROUP_ID; if (groupInfo.TYPE == 3) //获取门店信息 { MDSearch storeInfo = _storeRepo.GetByGroupId(groupInfo.ID); if (storeInfo != null) { deptInfo.StoreType = storeInfo.StoreType.HasValue ? storeInfo.StoreType.Value : 1; deptInfo.IsPickUp = storeInfo.IS_PICK_UP.HasValue ? storeInfo.IS_PICK_UP.Value : false; deptInfo.GroupID = storeInfo.GROUP_ID.HasValue ? storeInfo.GROUP_ID.Value : 0; deptInfo.Address = storeInfo.Address; deptInfo.Telephone = storeInfo.Phone; deptInfo.Latitude = storeInfo.X; deptInfo.Longitude = storeInfo.Y; deptInfo.BelongsAreaNo = storeInfo.BelongsAreaNo; deptInfo.Province = storeInfo.Province; deptInfo.City = storeInfo.City; deptInfo.Area = storeInfo.Area; deptInfo.Brand = storeInfo.PP; } } } return(deptInfo); }
public BaseDeptInfo GetGroupInfo(int groupId) { GROUP_INFO groupInfo = _groupRepo.Get(groupId); if (groupInfo != null) { BaseDeptInfo deptInfo = new BaseDeptInfo(); deptInfo.ID = groupInfo.ID; deptInfo.DeptName = groupInfo.NAME; deptInfo.DeptCode = groupInfo.CODE; deptInfo.Type = groupInfo.TYPE; deptInfo.MagentoGroupID = groupInfo.MAGENTO_GROUP_ID; deptInfo.Order = groupInfo.WX_ORDER.HasValue ? groupInfo.WX_ORDER.Value : 0; deptInfo.ParentID = groupInfo.PARENT_ID; //deptInfo.DeptType = (byte)deptInfo.Type; deptInfo.WXGroupID = groupInfo.WX_GROUP_ID; return(deptInfo); } return(null); }
public int SaveEmployee(string accessToken, EMPLOYEE entity, DeptInfo dept, ref string errMsg) { using (TransScope scope = new TransScope()) { int wxGroupId = 0, deptId = dept.ID; GROUP_INFO groupInfo = null; if (entity.ID > 0) { var rel = _empRepo.GetGroupIdByEmpID(entity.ID); deptId = rel; } groupInfo = _groupRepo.Get(deptId); if (groupInfo == null) { return(0); } wxGroupId = groupInfo.WX_GROUP_ID; List <int> department = new List <int>() { wxGroupId }; string gender = entity.GENDER.HasValue ? entity.GENDER.Value.ToString() : null; int rows = 0; if (entity.ID == 0) { var response = WXQYClientServiceApi.Create().CreateUser(accessToken, entity.USERID, entity.NAME, department, entity.POSITION, entity.MOBILE, gender, entity.EMAIL, entity.WECHAT_ID); if (response != null && response.ErrorCode == 0) { //同步头像 UserInfo user = WXQYClientServiceApi.Create().GetUser(accessToken, entity.USERID); if (user != null) { entity.AVATAR_URL = user.Avatar; } entity.STATUS = 4; entity.CREATE_TIME = DateTime.Now; rows = (int)_empRepo.Insert(entity); entity.ID = rows; //修改关系表 if (rows > 0) { //删除所有员工关系 _empRepo.DeleteRelByEmpID(entity.ID); //新增关系 REL_EMP_GROUP rel = new REL_EMP_GROUP(); rel.TYPE = groupInfo.TYPE; rel.EMP_ID = entity.ID; rel.GROUP_ID = deptId; rel.CREATE_TIME = DateTime.Now; rel.CREATE_USER = "******"; _empRepo.Insert(rel); } } else { errMsg = response.ErrorMessage; } } else { var response = WXQYClientServiceApi.Create().UpdateUser(accessToken, entity.USERID, entity.NAME, department, entity.POSITION, entity.MOBILE, gender, entity.EMAIL, entity.WECHAT_ID); if (response != null && response.ErrorCode == 0) { //同步头像 UserInfo user = WXQYClientServiceApi.Create().GetUser(accessToken, entity.USERID); if (user != null) { entity.AVATAR_URL = user.Avatar; } entity.FullUpdate = false; rows = _empRepo.Update(entity); } else { errMsg = response.ErrorMessage; } } scope.Commit(); return(rows); } }
public int ModifyDept(DeptInfo deptInfo, string accessToken, ref string errMsg) { int rows = 0, rootId = AppConfig.QYDeptRootID; GROUP_INFO existGroupInfo = _groupRepo.Get(deptInfo.ID); if (existGroupInfo != null) { int wxParentId = 0; if (existGroupInfo.PARENT_ID == 0) { wxParentId = rootId; } else { GROUP_INFO parentInfo = _groupRepo.Get(existGroupInfo.PARENT_ID); if (parentInfo != null) { wxParentId = parentInfo.WX_GROUP_ID; } } DeptResponse response = WXQYClientServiceApi.Create().UpdateDept(accessToken, existGroupInfo.WX_GROUP_ID, deptInfo.DeptName, wxParentId, deptInfo.Order); if (response != null && response.ErrorCode == 0) { GROUP_INFO groupInfo = new GROUP_INFO(); groupInfo.ID = deptInfo.ID; groupInfo.NAME = deptInfo.DeptName; groupInfo.CODE = deptInfo.DeptCode; groupInfo.MAGENTO_GROUP_ID = deptInfo.MagentoGroupID; groupInfo.WX_ORDER = deptInfo.Order; groupInfo.LAST_MODIFY_TIME = DateTime.Now; groupInfo.LAST_MODIFY_USER = "******"; groupInfo.FullUpdate = false; rows = (int)_groupRepo.Update(groupInfo); if (rows > 0 && existGroupInfo.TYPE == 3) { MDSearch storeInfo = _storeRepo.GetByGroupId(deptInfo.ID); if (storeInfo == null) { storeInfo = new MDSearch(); } storeInfo.Name = deptInfo.DeptName; storeInfo.Code = deptInfo.DeptCode; storeInfo.StoreType = deptInfo.StoreType; storeInfo.IS_PICK_UP = deptInfo.IsPickUp; storeInfo.Address = deptInfo.Address; storeInfo.Phone = deptInfo.Telephone; storeInfo.X = deptInfo.Latitude; storeInfo.Y = deptInfo.Longitude; storeInfo.BelongsAreaNo = deptInfo.BelongsAreaNo; storeInfo.Province = deptInfo.Province; storeInfo.City = deptInfo.City; storeInfo.Area = deptInfo.Area; storeInfo.PP = deptInfo.Brand; if (storeInfo.ID > 0) { storeInfo.FullUpdate = false; _storeRepo.Update(storeInfo); } else { storeInfo.GROUP_ID = deptInfo.ID; _groupRepo.Insert(storeInfo); } } } else { errMsg = response.ErrorMessage; } } return(rows); }
public int CreateDept(DeptInfo deptInfo, string accessToken, ref string errMsg) { int groupId = 0, wxParentId = 0, rootId = AppConfig.QYDeptRootID; GROUP_INFO groupInfo = null; if (deptInfo.ParentID == 0) //创建大区 { groupInfo = new GROUP_INFO(); groupInfo.TYPE = 1; wxParentId = rootId;//根目录ID } else { GROUP_INFO parentDept = _groupRepo.Get(deptInfo.ParentID); if (parentDept != null) { groupInfo = new GROUP_INFO(); wxParentId = parentDept.WX_GROUP_ID; if (parentDept.TYPE == 1) //如果父级是大区,则创建区域 { groupInfo.TYPE = 2; } else if (parentDept.TYPE == 2) { groupInfo.TYPE = 3; } } } if (groupInfo != null) { groupInfo.NAME = deptInfo.DeptName; groupInfo.CODE = deptInfo.DeptCode; groupInfo.PARENT_ID = deptInfo.ParentID; groupInfo.MAGENTO_GROUP_ID = deptInfo.MagentoGroupID; groupInfo.WX_ORDER = deptInfo.Order; groupInfo.CREATE_TIME = DateTime.Now; groupInfo.CREATE_USER = "******"; DeptResponse response = WXQYClientServiceApi.Create().CreateDept(accessToken, groupInfo.NAME, wxParentId, groupInfo.WX_ORDER.Value); if (response != null && response.ErrorCode == 0) { groupInfo.WX_GROUP_ID = response.ID; groupInfo.WX_PARENT_ID = wxParentId; groupId = (int)_groupRepo.Insert(groupInfo); if (groupId > 0 && groupInfo.TYPE == 3) //创建MDSearch { MDSearch storeInfo = new MDSearch(); storeInfo.Name = deptInfo.DeptName; storeInfo.Code = deptInfo.DeptCode; storeInfo.StoreType = deptInfo.StoreType; storeInfo.IS_PICK_UP = deptInfo.IsPickUp; storeInfo.Address = deptInfo.Address; storeInfo.Phone = deptInfo.Telephone; storeInfo.X = deptInfo.Latitude; storeInfo.Y = deptInfo.Longitude; storeInfo.BelongsAreaNo = deptInfo.BelongsAreaNo; storeInfo.Province = deptInfo.Province; storeInfo.City = deptInfo.City; storeInfo.Area = deptInfo.Area; storeInfo.PP = deptInfo.Brand; storeInfo.GROUP_ID = groupId; _groupRepo.Insert(storeInfo); } deptInfo.Type = groupInfo.TYPE; } else { errMsg = response.ErrorMessage; } } return(groupId); }