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 AdmGoodsRecordService: IAdmGoodsRecordService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public AdmGoodsRecordService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
|
public ResultEntity save(AdmGoodsRecordDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
var AdmGoodsRecord = _mapper.Map<AdmGoodsRecord>(dto);
|
if (String.IsNullOrEmpty(AdmGoodsRecord.Id))
|
{
|
AdmGoodsRecord.Id = Guid.NewGuid().ToString();
|
dto.Id = AdmGoodsRecord.Id;
|
|
_context.AdmGoodsRecords.Add(AdmGoodsRecord);
|
}
|
else
|
{
|
var updatepltRole = _context.AdmGoodsRecords.Find(AdmGoodsRecord.Id);
|
updatepltRole.GoodsId = AdmGoodsRecord.GoodsId;
|
updatepltRole.RecordTypeId = AdmGoodsRecord.RecordTypeId;
|
updatepltRole.GoodsNum = AdmGoodsRecord.GoodsNum;
|
updatepltRole.GoodsLeft = AdmGoodsRecord.GoodsLeft;
|
|
|
|
updatepltRole.OperationalMatters = AdmGoodsRecord.OperationalMatters;
|
updatepltRole.Remark = AdmGoodsRecord.Remark;
|
|
|
|
updatepltRole.RecStatus = AdmGoodsRecord.RecStatus;
|
// updatepltRole.Creater = pltRole.Creater;
|
//updatepltRole.Createtime = pltRole.Createtime;
|
updatepltRole.Modifier = AdmGoodsRecord.Modifier;
|
updatepltRole.Modifytime = AdmGoodsRecord.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = AdmGoodsRecord.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public AdmGoodsRecordDTO Get(string id)
|
{
|
var entity = _context.AdmGoodsRecords.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new AdmGoodsRecord();
|
}
|
var AdmGoodsRecordDTO = _mapper.Map<AdmGoodsRecordDTO>(entity);
|
return AdmGoodsRecordDTO;
|
}
|
|
public ResultDataEntity<AdmGoodsRecordDTO> SearchByPaging(AdmGoodsRecordDTOSearch searchEntity)
|
{
|
ResultDataEntity<AdmGoodsRecordDTO> data = new ResultDataEntity<AdmGoodsRecordDTO>();
|
|
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 XdTimestart = DateTime.Now;
|
DateTime XdTimeend = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(searchEntity.Createtime))
|
{
|
string[] XdTimes = searchEntity.Createtime.Split("|");
|
DateTime.TryParse(XdTimes[0], out XdTimestart);
|
DateTime.TryParse(XdTimes[1], out XdTimeend);
|
XdTimeend = XdTimeend.AddDays(1);
|
}
|
var query = (from a in _context.AdmGoodsRecords//.Where(x => x.RecStatus == "A")
|
join z in _context.AdmGoodsManages on a.GoodsId equals z.Id
|
|
|
join c in listCode.Where(x => x.CodeTable == "adm_goods_record" && x.CodeField == "RecordTypeId")
|
on a.RecordTypeId equals c.CodeSn
|
|
|
|
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.Createtime) || (a.Createtime >= XdTimestart && a.Createtime <= XdTimeend))
|
|
|
&& (string.IsNullOrWhiteSpace(searchEntity.OperationalMatters) || a.OperationalMatters.Contains(searchEntity.OperationalMatters.Trim()))
|
|
&& (string.IsNullOrWhiteSpace(searchEntity.RecordTypeId) || a.RecordTypeId == searchEntity.RecordTypeId.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.GoodsId) || a.GoodsId == searchEntity.GoodsId.Trim())
|
|
select new AdmGoodsRecordDTO
|
{
|
Id = a.Id,
|
|
|
|
RecordTypeId = a.RecordTypeId,
|
RecordTypeName = c.Comments,
|
GoodsId = a.GoodsId,
|
GoodsName = z.GoodsName,
|
|
OperationalMatters = a.OperationalMatters,
|
Remark = a.Remark,
|
CreatetimeName = a.Createtime.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
|
RecStatus = a.RecStatus,
|
GoodsNum = a.GoodsNum ?? 0,
|
GoodsLeft = a.GoodsLeft ?? 0,
|
|
}).OrderByDescending(x => x.Createtime).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.AdmGoodsRecords.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<AdmGoodsRecordDTO> GetList()
|
{
|
|
|
var listPosition = _context.AdmGoodsRecords.Where(r => r.RecStatus == "A").ToList();
|
|
var list = _mapper.Map<List<AdmGoodsRecordDTO>>(listPosition);
|
return list;
|
}
|
}
|
}
|