using AutoMapper;
|
using DTO;
|
using IServices;
|
using Microsoft.EntityFrameworkCore;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using zhengcaioa.Models;
|
|
|
namespace Services
|
{
|
public class HrJixiaotichengService : IHrJixiaotichengService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public HrJixiaotichengService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
|
public ResultEntity save(HrJixiaotichengDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
var model = _mapper.Map<HrJixiaoticheng>(dto);
|
if (String.IsNullOrEmpty(model.Id))
|
{
|
model.Id = Guid.NewGuid().ToString();
|
|
|
_context.HrJixiaotichengs.Add(model);
|
}
|
else
|
{
|
var updatepltRole = _context.HrJixiaotichengs.Find(model.Id);
|
updatepltRole.PostId = model.PostId;
|
updatepltRole.PiecerateId = model.PiecerateId;
|
updatepltRole.Tichengstandard = model.Tichengstandard;
|
updatepltRole.Renwustandard = model.Renwustandard;
|
updatepltRole.Ticheng = model.Ticheng;
|
updatepltRole.Renwu = model.Renwu;
|
|
|
updatepltRole.Effecttime = model.Effecttime;
|
|
updatepltRole.RecStatus = model.RecStatus;
|
// updatepltRole.Creater = pltRole.Creater;
|
//updatepltRole.Createtime = pltRole.Createtime;
|
updatepltRole.Modifier = model.Modifier;
|
updatepltRole.Modifytime = model.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = model.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public HrJixiaotichengDTO Get(string id)
|
{
|
var entity = _context.HrJixiaotichengs.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new HrJixiaoticheng();
|
}
|
var HrJixiaotichengDTO = _mapper.Map<HrJixiaotichengDTO>(entity);
|
return HrJixiaotichengDTO;
|
}
|
|
public ResultDataEntity<HrJixiaotichengDTO> SearchByPaging(HrJixiaotichengDTOSearch searchEntity)
|
{
|
ResultDataEntity<HrJixiaotichengDTO> data = new ResultDataEntity<HrJixiaotichengDTO>();
|
|
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
|
}
|
);
|
|
var query = (from a in _context.HrJixiaotichengs//.Where(x => x.RecStatus == "A")
|
join b in listCode.Where(x => x.CodeTable == "fi_piecerate" && x.CodeField == "standard")
|
on a.Tichengstandard equals b.CodeSn
|
into bsssss
|
from bbb in bsssss.DefaultIfEmpty()
|
|
join c in listCode.Where(x => x.CodeTable == "hr_jixiaoticheng" && x.CodeField == "renwustandard")
|
on a.Renwustandard equals c.CodeSn
|
into csssss
|
from ccc in csssss.DefaultIfEmpty()
|
|
join f in _context.HrPositions
|
on a.PostId equals f.Id
|
into fsssss
|
from fff in fsssss.DefaultIfEmpty()
|
|
join g in _context.FiPiecerates
|
on a.PiecerateId equals g.Id
|
into gsssss
|
from ggg in gsssss.DefaultIfEmpty()
|
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.PostId) || a.PostId == searchEntity.PostId.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.PiecerateId) || a.PiecerateId == searchEntity.PiecerateId.Trim())
|
select new HrJixiaotichengDTO
|
{
|
Id = a.Id,
|
PostId = a.PostId,
|
PostName = fff.PostName,
|
PiecerateId = a.PiecerateId,
|
PiecerateName = ggg.Project,
|
Renwustandard = a.Renwustandard,
|
RenwustandardName = ccc.Comments,
|
Tichengstandard = a.Tichengstandard,
|
TichengstandardName = bbb.Comments,
|
Ticheng = a.Ticheng,
|
Renwu = a.Renwu,
|
|
|
TichengName = a.Ticheng.HasValue ? a.Ticheng.Value.ToString("F2") : "",
|
RenwuName = a.Renwu.HasValue ? a.Renwu.Value.ToString("F2") : "",
|
|
Effecttime = a.Effecttime,
|
EffecttimeName = a.Effecttime.HasValue ? a.Effecttime.Value.ToString("yyyy-MM-dd") : "",
|
|
|
|
|
RecStatus = a.RecStatus,
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
|
}).OrderByDescending(x => x.Modifytime).ToList();
|
|
|
|
|
|
|
|
//if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
var rolelist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
|
data.LoadData(searchEntity, rolelist);
|
return data;
|
}
|
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.HrJixiaotichengs.Find(id);
|
if (model != null)
|
{
|
model.RecStatus = "D";
|
model.Modifier = userid;
|
model.Modifytime = DateTime.Now;
|
_context.SaveChanges();
|
}
|
|
return result;
|
}
|
|
|
/// <summary>
|
/// 获取所有有效角色
|
/// </summary>
|
/// <returns></returns>
|
public List<HrJixiaotichengDTO> GetList()
|
{
|
|
|
var listPosition = _context.HrJixiaotichengs.Where(r => r.RecStatus == "A").ToList();
|
|
var list = _mapper.Map<List<HrJixiaotichengDTO>>(listPosition);
|
return list;
|
}
|
}
|
}
|