using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using AutoMapper;
|
using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.EntityFrameworkCore;
|
using zhengcaioa.Models;
|
|
|
namespace Services
|
{
|
public class GroupTuiguangService: IGroupTuiguangService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public GroupTuiguangService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
|
public ResultEntity save(GroupTuiguangDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
|
|
|
|
var groupTuiguang = _mapper.Map<GroupTuiguang>(dto);
|
|
|
if (String.IsNullOrEmpty(groupTuiguang.Id))
|
{
|
groupTuiguang.Id = Guid.NewGuid().ToString();
|
_context.GroupTuiguangs.Add(groupTuiguang);
|
}
|
else
|
{
|
var updateproject = _context.GroupTuiguangs.Find(groupTuiguang.Id);
|
|
updateproject.GroupId = groupTuiguang.GroupId;
|
updateproject.TgTime = groupTuiguang.TgTime;
|
updateproject.Tuiguangcontent = groupTuiguang.Tuiguangcontent;
|
updateproject.RecStatus = groupTuiguang.RecStatus;
|
updateproject.Modifier = groupTuiguang.Modifier;
|
updateproject.Modifytime = groupTuiguang.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = groupTuiguang.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public GroupTuiguangDTO Get(string id)
|
{
|
|
var entity = _context.GroupTuiguangs.Find(id);
|
if (entity.RecStatus != "A")
|
{
|
entity = new GroupTuiguang();
|
}
|
|
|
var GroupTuiguangDTO = _mapper.Map<GroupTuiguangDTO>(entity);
|
|
|
return GroupTuiguangDTO;
|
}
|
|
public ResultDataEntity<GroupTuiguangDTO> SearchByPaging(GroupTuiguangDTOSearch searchEntity)
|
{
|
|
|
|
ResultDataEntity<GroupTuiguangDTO> data = new ResultDataEntity<GroupTuiguangDTO>();
|
List<GroupTuiguangDTO> list = new List<GroupTuiguangDTO>();
|
|
|
|
|
|
|
|
DateTime TgTimestart = DateTime.Now;
|
DateTime TgTimeend = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(searchEntity.TgTime))
|
{
|
string[] TgTimes = searchEntity.TgTime.Split("|");
|
DateTime.TryParse(TgTimes[0], out TgTimestart);
|
DateTime.TryParse(TgTimes[1], out TgTimeend);
|
// TgTimeend = TgTimeend.AddDays(1);
|
}
|
|
|
var query = (from a in _context.GroupTuiguangs
|
|
join e in _context.PltUsers.Where(x => x.RecStatus == "A" && x.Zhiwustatus == "A" && x.IsYwjl == "A")
|
on a.Creater equals e.Id
|
|
join d in _context.GroupGroups.Where(x => x.RecStatus == "A" )
|
on a.GroupId equals d.Id
|
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.TgTime) || (a.TgTime >= TgTimestart && a.TgTime <= TgTimeend))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Creater) || e.UserName.Contains(searchEntity.Creater.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.GroupId) || a.GroupId == searchEntity.GroupId.Trim())
|
|
|
select new GroupTuiguangDTO
|
{
|
Id = a.Id,
|
GroupId = a.GroupId,
|
TgTime = a.TgTime,
|
Tuiguangcontent = a.Tuiguangcontent,
|
Qunnumber = d.Qunnumber,
|
Qunzhuname = d.Qunzhuname,
|
RecStatus = a.RecStatus,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
TgTimeName = a.TgTime.ToString("yyyy-MM-dd"),
|
CreaterName = e.UserName,
|
}
|
).OrderByDescending(x => x.Modifytime).ToList();
|
|
|
|
//if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
data.LoadData(searchEntity, lianlist);
|
return data;
|
}
|
|
|
|
|
|
|
/// <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.GroupTuiguangs.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
}
|
}
|