123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using Central.Control.Domain;
- using MES.Production.Service.IService;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace MES.Production.Service.ServiceImp
- {
- /// <summary>
- /// 岗位部门关系业务实现类
- /// add 作者: 季健国 QQ:181589805 by 2016-09-10
- /// </summary>
- public class PostDepartmentManage : RepositoryBase<SYS_POST_DEPARTMENT>, IService.IPostDepartmentManage
- {
- /// <summary>
- /// 岗位人员
- /// </summary>
- IPostUserManage PostUserManage { get; set; }
- /// <summary>
- /// 根据部门ID获取岗位集合
- /// </summary>
- public List<SYS_POST> GetPostIDByDptId(string dptId)
- {
- return this.LoadAll(p => dptId == p.FK_DEPARTMENT_ID).Select(p => p.SYS_POST).ToList();
- }
- /// <summary>
- /// 根据岗位ID获取所应用部门的集合
- /// </summary>
- public List<SYS_DISTRIBUTORS> GetDptIDByPostID(string postId)
- {
- return this.LoadAll(p => postId == p.FK_POST_ID).Select(p => p.SYS_DISTRIBUTORS).ToList();
- }
- /// <summary>
- /// 根据部门获取部门岗位,供人员选择岗位使用
- /// </summary>
- public dynamic GetPostDptInfoByDptId(string dptId)
- {
- string sql = @"select d.name+'-'+ p.postname as postname,
- C.NAMETEXT AS posttype,s.id
- from sys_post p inner join Sys_Post_Department s
- on p.id=s.fk_post_id inner join SYS_DISTRIBUTORS d
- on s.fk_department_id=d.id
- left join sys_code c on p.posttype=c.codevalue and c.codetype='POSTTYPE'
- where s.fk_department_id in(" + dptId + ")";
- return this.ExecuteSqlQuery(sql);
- }
- /// <summary>
- /// 设置部门岗位
- /// </summary>
- public bool SetPost(string dptId, string postId,out string msg)
- {
- msg = string.Empty;
- var newpost = postId.Split(',').ToList();
- try
- {
- //----验证当前部门的岗位是否分配了人员
- //原有岗位是否存在
- if (this.IsExist(p => p.FK_DEPARTMENT_ID == dptId))
- {
- //原有岗位部门数据
- var originalPost = this.LoadAll(p => p.FK_DEPARTMENT_ID == dptId);
- var oldpost = originalPost.Select(p => p.FK_POST_ID).OrderBy(p => p).ToList();
- #region 对比当前选择的岗位与原有岗位是否一致
- //规则:1、判断数量 2、排序对比内项
- if (originalPost.Count() == newpost.Count && oldpost.All(newpost.Contains)) return true;
- #endregion
- #region 不一致处理
- //查找不一致的岗位记录,是否存在人员分配
- var differentPost = originalPost.Where(p => !postId.Contains(p.FK_POST_ID)).ToList();
- var differentPostDptId =
- differentPost.Aggregate(string.Empty, (current, t) => current + t.ID + ",").TrimEnd(',');
- //有人员分配返回false 并提示那个岗位分配了人员
- foreach (var item in differentPost.Select(c=>c.ID).ToList())
- {
- var postUser = this.PostUserManage.LoadAll(p => p.FK_POST_DEPARTMENTID == item).Select(p => p.SYS_POST_DEPARTMENT.SYS_POST.POSTNAME).GroupBy(p => p).ToList();
- if (postUser.Any())
- {
- msg += postUser[0].Key + " 岗位中存在人员,请先将人员分配其他岗位<br/>";
- }
- }
- if (!string.IsNullOrEmpty(msg)) return false;
- //删除原有岗位部门废弃的记录
- this.Delete(p => differentPostDptId.Contains(p.ID.ToString()));
- //移除原有不变的岗位ID
- postId = postId.PadRight(postId.Length + 1, ',');
- foreach (var item in originalPost.Where(c => postId.Contains(c.FK_POST_ID)).Select(c => c.FK_POST_ID).ToList())
- {
- postId = postId.Replace(item, "");
- }
- postId = postId.TrimStart(',').TrimEnd(',');
- #endregion
- }
- //保存新的数据
- if (!string.IsNullOrEmpty(postId))
- {
- var list = postId.Split(',').Select(item => new SYS_POST_DEPARTMENT()
- {
- FK_DEPARTMENT_ID = dptId,
- FK_POST_ID = item
- }).ToList();
- return this.SaveList(list) > 0;
- }
- return true;
- }
- catch (Exception e) { throw e.InnerException; }
- }
- }
- }
|