using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using IServices;
|
using DTO;
|
using zhengcaioa.Models;
|
using AutoMapper;
|
using System.Linq;
|
|
namespace Services
|
{
|
public partial class DailyManagementService : IDailyManagementService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public DailyManagementService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
#region 接电话管理
|
/// <summary>
|
/// 取通话记录列表
|
/// </summary>
|
/// <param name="search"></param>
|
/// <returns></returns>
|
public ResultDataEntity<AdmHoldPhoneDTO> GetHoldPhoneList(AdmHoldPhoneDTOSearch search)
|
{
|
var query = _context.AdmHoldPhones
|
.Where(e => e.RecStatus == "A")
|
.ToList();
|
if (!string.IsNullOrEmpty(search.Createtime))
|
{
|
var date = search.Createtime.Split('|');
|
DateTime startDate = Convert.ToDateTime(date[0]);
|
DateTime endDate = Convert.ToDateTime(date[1]);
|
query = query.Where(e => e.Createtime >= startDate && e.Createtime <= endDate.AddDays(1)).ToList();
|
|
}
|
if (!string.IsNullOrEmpty(search.Intention))
|
{
|
query = query.Where(e => e.Intention == search.Intention).ToList();
|
}
|
if (!string.IsNullOrEmpty(search.LineType))
|
{
|
query = query.Where(e => e.LineType == search.LineType).ToList();
|
}
|
if (!string.IsNullOrEmpty(search.Context))
|
{
|
query = query.Where(e => e.Context.Contains(search.Context)).ToList();
|
}
|
var dt = (from a in query
|
join b in _context.PltUsers.Where(e => e.RecStatus == "A")
|
on a.UserId equals b.Id
|
//join c in _context.sy
|
select new AdmHoldPhoneDTO
|
{
|
Id = a.Id,
|
InTime = a.InTime,
|
OrderId = a.OrderId,
|
Phone = a.Phone,
|
LineType = a.LineType,
|
Context = a.Context,
|
UserId = b.UserName,
|
Intention = a.Intention
|
|
}).ToList();
|
ResultDataEntity<AdmHoldPhoneDTO> data = new ResultDataEntity<AdmHoldPhoneDTO>();
|
if (search.totalrows == 0)
|
search.totalrows = dt.Count();
|
var signinList = dt.Skip((search.page - 1) * search.rows).Take(search.rows).ToList();
|
var list = _mapper.Map<List<AdmHoldPhoneDTO>>(signinList);
|
data.LoadData(search, list);
|
|
return data;
|
}
|
|
/// <summary>
|
/// 取单条通话记录
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public AdmHoldPhoneDTO GetHoldPhone(string id)
|
{
|
AdmHoldPhone entity = _context.AdmHoldPhones.Where(e => e.RecStatus == "A" && e.Id == id).FirstOrDefault();
|
if (entity == null)
|
{
|
entity = new AdmHoldPhone();
|
}
|
AdmHoldPhoneDTO holdPhone = _mapper.Map<AdmHoldPhoneDTO>(entity);
|
return holdPhone;
|
}
|
|
/// <summary>
|
/// 保存接电话信息
|
/// </summary>
|
/// <param name="holdPhone"></param>
|
/// <returns></returns>
|
public ResultEntity SaveHoldPhone(AdmHoldPhoneDTO holdPhone)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
AdmHoldPhone hold = _mapper.Map<AdmHoldPhone>(holdPhone);
|
if (string.IsNullOrEmpty(hold.Id))
|
{
|
hold.Id = Guid.NewGuid().ToString();
|
holdPhone.Id = hold.Id;
|
|
_context.AdmHoldPhones.Add(hold);
|
}
|
else
|
{
|
var entity = _context.AdmHoldPhones.Find(hold.Id);
|
entity.OrderId = holdPhone.OrderId;
|
entity.UserId = holdPhone.UserId;
|
entity.LineType = holdPhone.LineType;
|
entity.Intention = holdPhone.Intention;
|
entity.Handling = holdPhone.Handling;
|
entity.Phone = holdPhone.Phone;
|
entity.Context = holdPhone.Context;
|
}
|
_context.SaveChanges();
|
resultEntity.ReturnID = hold.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
ex.Message.ToString();
|
}
|
return resultEntity;
|
}
|
|
/// <summary>
|
/// 修改记录状态
|
/// </summary>
|
/// <param name="id">主id</param>
|
/// <param name="userid">用户</param>
|
/// <returns></returns>
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.AdmHoldPhones.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
|
#endregion
|
|
#region 工作提醒
|
|
/// <summary>
|
/// 工作提醒列表
|
/// </summary>
|
/// <param name="search"></param>
|
/// <returns></returns>
|
public ResultDataEntity<AdmMemoBookDTO> GetMemoBookList(AdmMemoBookDTOSearch search)
|
{
|
|
var listCode = (from a in _context.SysCodeDtls
|
join b in _context.SysCodes
|
on a.CodeId equals b.Id
|
where a.RecStatus == "A"
|
&& b.RecStatus == "A"
|
select new CodeDataEntity()
|
{
|
CodeId = b.Id,
|
CodeTable = b.CodeTable,
|
CodeField = b.CodeField,
|
CodeSn = a.CodeSn,
|
Comments = a.Comments,
|
Contents = a.Contents,
|
RecStatus = a.RecStatus,
|
Sort = a.Sort
|
});
|
DateTime Createtimestart = DateTime.Now;
|
DateTime Createtimeend = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(search.Createtime))
|
{
|
string[] Createtimes = search.Createtime.Split("|");
|
DateTime.TryParse(Createtimes[0], out Createtimestart);
|
DateTime.TryParse(Createtimes[1], out Createtimeend);
|
Createtimeend = Createtimeend.AddDays(1);
|
}
|
|
|
var dt = (from a in _context.AdmMemoBooks
|
join b in _context.PltUsers.Where(e => e.RecStatus == "A")
|
on a.ToUserId equals b.Id
|
// join d in _context.HrDepts
|
//on b.DeptId equals d.Id
|
|
join c in _context.PltUsers.Where(e => e.RecStatus == "A")
|
on a.Creater equals c.Id
|
|
join f in listCode.Where(x => x.CodeTable == "ADM_MemoBook" && x.CodeField == "KaoHe")
|
on a.KaoHe equals f.CodeSn into fsss
|
from fff in fsss.DefaultIfEmpty()
|
|
|
join g in listCode.Where(x => x.CodeTable == "ADM_MemoBook" && x.CodeField == "RType")
|
on a.Rtype equals g.CodeSn into gsss
|
from ggg in gsss.DefaultIfEmpty()
|
|
join h in listCode.Where(x => x.CodeTable == "ADM_MemoBook" && x.CodeField == "HaveRead")
|
on a.Rtype equals h.CodeSn into hsss
|
from hhh in hsss.DefaultIfEmpty()
|
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(search.Createtime) || (a.Createtime >= Createtimestart && a.Createtime <= Createtimeend))
|
&& (string.IsNullOrWhiteSpace(search.Rtype) || a.Rtype == search.Rtype.Trim())
|
&& (string.IsNullOrWhiteSpace(search.Creater) || a.Creater == search.Creater.Trim())
|
|
&& (search.unread != 1 || a.HaveRead == 0)
|
&& (string.IsNullOrWhiteSpace(search.HaveRead) || a.HaveRead == int.Parse(search.HaveRead))
|
&& (string.IsNullOrWhiteSpace(search.ToUserId) || a.ToUserId == search.ToUserId.Trim())
|
&& (string.IsNullOrWhiteSpace(search.WorkDept) || a.WorkDept == search.WorkDept.Trim())
|
&& (string.IsNullOrWhiteSpace(search.KaoHe) || a.KaoHe == search.KaoHe)
|
|
select new AdmMemoBookDTO
|
{
|
Id = a.Id,
|
Rtype = a.Rtype,
|
RtypeName = ggg.Comments,
|
Creater = c.UserName,
|
ToUserId = b.UserName,
|
Time = a.Time,
|
TimeName = a.Time.HasValue ? a.Time.Value.ToString("yyyy-MM-dd HH:mm") : "",
|
Context = a.Context,
|
Createtime = a.Createtime,
|
FeedBack = a.FeedBack,
|
WorkDept = b.DeptId,
|
KaoHe = a.KaoHe,
|
KaoHeName = fff.Comments,
|
ZhuiZe = a.ZhuiZe,
|
WanchengTime = a.WanchengTime,
|
WanchengTimeName = a.WanchengTime.HasValue? a.WanchengTime.Value.ToString("yyyy-MM-dd HH:mm"): "",
|
BanLi = a.BanLi,
|
ShenSu = a.ShenSu,
|
ShenSuTime = a.ShenSuTime,
|
HaveRead = a.HaveRead.HasValue? a.HaveRead.Value:0,
|
HaveReadName = hhh.Comments,
|
|
}).OrderByDescending(x=>x.Createtime).ToList();
|
|
//if (!string.IsNullOrEmpty(search.Createtime))
|
//{
|
// var date = search.Createtime.Split('|');
|
// DateTime startDate = Convert.ToDateTime(date[0]);
|
// DateTime endDate = Convert.ToDateTime(date[1]);
|
// dt = dt.Where(e => e.Createtime >= startDate && e.Createtime <= endDate.AddDays(1)).ToList();
|
|
//}
|
//if (!string.IsNullOrEmpty(search.Rtype))
|
//{
|
// dt = dt.Where(e => e.Rtype == search.Rtype).ToList();
|
//}
|
//if (!string.IsNullOrEmpty(search.Creater))
|
//{
|
// dt = dt.Where(e => e.Creater == search.Creater).ToList();
|
//}
|
//int? iii = 0;
|
//if (search.unread == 1)
|
//{
|
// dt = dt.Where(e => e.HaveRead == iii).ToList();
|
//}
|
|
//if (!string.IsNullOrEmpty(search.HaveRead))
|
//{
|
// int aaa = int.Parse(search.HaveRead);
|
// dt = dt.Where(e => e.HaveRead == aaa).ToList();
|
//}
|
//if (!string.IsNullOrEmpty(search.ToUserId))
|
//{
|
// dt = dt.Where(e => e.ToUserId == search.ToUserId).ToList();
|
//}
|
//if (!string.IsNullOrEmpty(search.WorkDept))
|
//{
|
// dt = dt.Where(e => e.WorkDept == search.WorkDept).ToList();
|
//}
|
|
ResultDataEntity<AdmMemoBookDTO> data = new ResultDataEntity<AdmMemoBookDTO>();
|
if (search.totalrows == 0)
|
search.totalrows = dt.Count();
|
var dtList = dt.Skip((search.page - 1) * search.rows).Take(search.rows).ToList();
|
var list = _mapper.Map<List<AdmMemoBookDTO>>(dtList);
|
data.LoadData(search, list);
|
return data;
|
}
|
|
/// <summary>
|
/// 某一个人的工作提醒
|
/// </summary>
|
/// <param name="userid">用户ID</param>
|
/// <returns></returns>
|
public int GetRemind(string userid)
|
{
|
var query = _context.AdmMemoBooks
|
.Where(e => e.RecStatus == "A" && e.ToUserId == userid && e.HaveRead == 0 /*&& e.Time >= DateTime.Now && e.Rtype == "1"*/)
|
.ToList();
|
//var dt = (from a in query
|
// join b in _context.PltUsers.Where(e => e.RecStatus == "A")
|
// on a.Creater equals b.Id
|
// select new AdmMemoBookDTO
|
// {
|
// Id = a.Id,
|
// Rtype = a.Rtype,
|
// Creater = b.UserName,
|
// Time = a.Time,
|
// Context = a.Context,
|
// Createtime = a.Createtime
|
// }).ToList();
|
return query.Count;
|
}
|
public ResultEntity SaveMemoBook(AdmMemoBookDTO mbDTO)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
AdmMemoBook mb = _mapper.Map<AdmMemoBook>(mbDTO);
|
if (string.IsNullOrEmpty(mb.Id))
|
{
|
mb.Id = Guid.NewGuid().ToString();
|
mb.Id = mb.Id;
|
// mb.HaveRead = 0;
|
// mb.KaoHe = "1";
|
|
_context.AdmMemoBooks.Add(mb);
|
}
|
else
|
{
|
var book = _context.AdmMemoBooks.Find(mb.Id);
|
if(book.HaveRead == 1)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "已完成的提醒不能修改";
|
return resultEntity;
|
}
|
book.HaveRead = mb.HaveRead;
|
book.Context = mb.Context;
|
book.ToUserId = mb.ToUserId;
|
book.Time = mb.Time;
|
book.Modifier = mb.Modifier;
|
book.Modifytime = mb.Modifytime;
|
book.FeedBack = mb.FeedBack;
|
book.WorkDept = mb.WorkDept;
|
book.KaoHe = mb.KaoHe;
|
book.ZhuiZe = mb.ZhuiZe;
|
book.WanchengTime = mb.WanchengTime;
|
book.BanLi = mb.BanLi;
|
book.ShenSu = mb.ShenSu;
|
book.ShenSuTime = mb.ShenSuTime;
|
}
|
_context.SaveChanges();
|
resultEntity.ReturnID = mb.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
ex.Message.ToString();
|
}
|
return resultEntity;
|
}
|
|
|
public ResultEntity SaveMemoBookKaohe(AdmMemoBookDTO mbDTO)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
AdmMemoBook mb = _mapper.Map<AdmMemoBook>(mbDTO);
|
if (string.IsNullOrEmpty(mb.Id))
|
{
|
mb.Id = Guid.NewGuid().ToString();
|
mb.Id = mb.Id;
|
// mb.HaveRead = 0;
|
// mb.KaoHe = "1";
|
|
_context.AdmMemoBooks.Add(mb);
|
}
|
else
|
{
|
var book = _context.AdmMemoBooks.Find(mb.Id);
|
|
book.HaveRead = mb.HaveRead;
|
book.Context = mb.Context;
|
book.ToUserId = mb.ToUserId;
|
book.Time = mb.Time;
|
book.Modifier = mb.Modifier;
|
book.Modifytime = mb.Modifytime;
|
book.FeedBack = mb.FeedBack;
|
book.WorkDept = mb.WorkDept;
|
book.KaoHe = mb.KaoHe;
|
book.ZhuiZe = mb.ZhuiZe;
|
book.WanchengTime = mb.WanchengTime;
|
book.BanLi = mb.BanLi;
|
book.ShenSu = mb.ShenSu;
|
book.ShenSuTime = mb.ShenSuTime;
|
}
|
_context.SaveChanges();
|
resultEntity.ReturnID = mb.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
ex.Message.ToString();
|
}
|
return resultEntity;
|
}
|
|
|
/// <summary>
|
/// 备忘状态
|
/// </summary>
|
/// <param name="id">主id</param>
|
/// <param name="userid">用户</param>
|
/// <returns></returns>
|
public ResultEntity ModifyMemoBookStatus(string id, string userid ,bool isReaded = false)
|
{
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.AdmMemoBooks.Find(id);
|
if (model != null)
|
{
|
if (isReaded)
|
{
|
model.HaveRead = 1;
|
}
|
else
|
{
|
model.RecStatus = "D";
|
}
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
/// <summary>
|
/// 单条提醒记录
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public AdmMemoBookDTO GetMemoBook(string id)
|
{
|
AdmMemoBook entity = _context.AdmMemoBooks.Where(e => e.RecStatus == "A" && e.Id == id).FirstOrDefault();
|
if (entity == null)
|
{
|
entity = new AdmMemoBook();
|
}
|
AdmMemoBookDTO memobook = _mapper.Map<AdmMemoBookDTO>(entity);
|
return memobook;
|
}
|
#endregion
|
|
}
|
}
|