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 FiAccountService: IFiAccountService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public FiAccountService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
|
public ResultEntity save(FiAccountDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
var fiAccount = _mapper.Map<FiAccount>(dto);
|
if (String.IsNullOrEmpty(fiAccount.Id))
|
{
|
fiAccount.Id = Guid.NewGuid().ToString();
|
|
|
_context.FiAccounts.Add(fiAccount);
|
}
|
else
|
{
|
var updatepltRole = _context.FiAccounts.Find(fiAccount.Id);
|
updatepltRole.Accounttype = fiAccount.Accounttype;
|
updatepltRole.Accountname = fiAccount.Accountname;
|
updatepltRole.Account = fiAccount.Account;
|
updatepltRole.Zzr = fiAccount.Zzr;
|
updatepltRole.Remark = fiAccount.Remark;
|
updatepltRole.QiyongStatus = fiAccount.QiyongStatus;
|
|
|
updatepltRole.Balance = fiAccount.Balance;
|
updatepltRole.AllIncome = fiAccount.AllIncome;
|
updatepltRole.AllExpenses = fiAccount.AllExpenses;
|
|
|
|
updatepltRole.RecStatus = fiAccount.RecStatus;
|
// updatepltRole.Creater = pltRole.Creater;
|
//updatepltRole.Createtime = pltRole.Createtime;
|
updatepltRole.Modifier = fiAccount.Modifier;
|
updatepltRole.Modifytime = fiAccount.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = fiAccount.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public FiAccountDTO Get(string id)
|
{
|
var entity = _context.FiAccounts.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new FiAccount();
|
}
|
var FiAccountDTO = _mapper.Map<FiAccountDTO>(entity);
|
return FiAccountDTO;
|
}
|
|
public ResultDataEntity<FiAccountDTO> SearchByPaging(FiAccountDTOSearch searchEntity)
|
{
|
ResultDataEntity<FiAccountDTO> data = new ResultDataEntity<FiAccountDTO>();
|
|
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.FiAccounts//.Where(x => x.RecStatus == "A")
|
join b in listCode.Where(x => x.CodeTable == "fi_account" && x.CodeField == "accounttype")
|
on a.Accounttype equals b.CodeSn
|
join f in listCode.Where(x => x.CodeTable == "system" && x.CodeField == "shifou")
|
on a.QiyongStatus equals f.CodeSn
|
where a.RecStatus == "A"
|
&& (string.IsNullOrWhiteSpace(searchEntity.Accountname) || a.Account.Contains(searchEntity.Accountname.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Accounttype) || a.Accounttype == searchEntity.Accounttype.Trim())
|
&& (string.IsNullOrWhiteSpace(searchEntity.QiyongStatus) || a.QiyongStatus == searchEntity.QiyongStatus.Trim())
|
select new FiAccountDTO
|
{
|
Id = a.Id,
|
Accounttype = a.Accounttype,
|
AccounttypeName = b.Comments,
|
Accountname = a.Accountname,
|
Account = a.Account,
|
Zzr = a.Zzr,
|
Remark = a.Remark,
|
RecStatus = a.RecStatus,
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
QiyongStatus = a.QiyongStatus,
|
QiyongStatusName = f.Comments,
|
AllIncome = a.AllIncome,
|
AllExpenses = a.AllExpenses,
|
Balance = a.Balance,
|
}).OrderByDescending(x => x.Modifytime).ToList();
|
|
|
|
|
|
|
|
//if (searchEntity.totalrows == 0)
|
searchEntity.totalrows = query.Count();
|
data.Heji1 = Math.Round(query.Sum(x => x.AllIncome) ?? 0, 2);
|
data.Heji2 = Math.Round(query.Sum(x => x.AllExpenses ?? 0), 2);
|
data.Heji3 = Math.Round(query.Sum(x => x.Balance ?? 0), 2);
|
var rolelist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
|
data.DangyeHeji1 = Math.Round(rolelist.Sum(x => x.AllIncome) ?? 0, 2);
|
data.DangyeHeji2 = Math.Round(rolelist.Sum(x => x.AllExpenses ?? 0), 2);
|
data.DangyeHeji3 = Math.Round(rolelist.Sum(x => x.Balance ?? 0), 2);
|
data.LoadData(searchEntity, rolelist);
|
return data;
|
}
|
|
public ResultEntity ModifyStatus(string id, string userid)
|
{
|
|
ResultEntity result = new ResultEntity();
|
result.Result = true;
|
|
var model = _context.FiAccounts.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<FiAccountDTO> GetList()
|
{
|
|
|
var listPosition = _context.FiAccounts.Where(r => r.RecStatus == "A" && r.QiyongStatus == "A" ).ToList();
|
|
var list = _mapper.Map<List<FiAccountDTO>>(listPosition);
|
return list;
|
}
|
}
|
}
|