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 OrderBanciService: IOrderBanciService
|
{
|
private readonly zhengcaioaContext _context;
|
private readonly IMapper _mapper;
|
public OrderBanciService(zhengcaioaContext context, IMapper mapper)
|
{
|
_context = context;
|
_mapper = mapper;
|
}
|
public ResultEntity save(OrderBanciDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
|
|
var entity = _mapper.Map<OrderBanci>(dto);
|
|
|
if (String.IsNullOrEmpty(entity.Id))
|
{
|
entity.Id = Guid.NewGuid().ToString();
|
dto.Id = entity.Id;
|
_context.OrderBancis.Add(entity);
|
}
|
else
|
{
|
var updateproject = _context.OrderBancis.Find(entity.Id);
|
|
updateproject.Banci = entity.Banci;
|
updateproject.Shijian = entity.Shijian;
|
|
updateproject.Shijianend = entity.Shijianend;
|
updateproject.Didian = entity.Didian;
|
|
updateproject.RecStatus = entity.RecStatus;
|
updateproject.Modifier = entity.Modifier;
|
updateproject.Modifytime = entity.Modifytime;
|
updateproject.Mingcheng = entity.Mingcheng;
|
updateproject.Renshu = entity.Renshu;
|
updateproject.Hang = entity.Hang;
|
updateproject.Lie = entity.Lie;
|
}
|
if(entity.Hang.HasValue && entity.Lie.HasValue)
|
{
|
var orderBanciZuoweis = _context.OrderBanciZuoweis.Where(x =>x.RecStatus == "A" && x.BanciId == entity.Id).ToList();
|
|
|
|
for(int i=0;i< entity.Hang.Value; i++)
|
{
|
for (int j = 0; j < entity.Lie.Value; j++)
|
{
|
var orderBanciZuowei = orderBanciZuoweis.Where(x => x.RowNo == (i + 1) && x.ColNo == (j + 1)).FirstOrDefault();
|
if(orderBanciZuowei == null)
|
{
|
var orderBanciZuoweisss = new OrderBanciZuowei();
|
orderBanciZuoweisss.Id = Guid.NewGuid().ToString();
|
orderBanciZuoweisss.BanciId = entity.Id;
|
orderBanciZuoweisss.ZuoweiId = (i + 1)+"-"+ (j + 1);
|
orderBanciZuoweisss.SeatNo = (i + 1) + "-" + (j + 1) + "座";
|
orderBanciZuoweisss.Status = "0";
|
orderBanciZuoweisss.RowNo = (i+1);
|
orderBanciZuoweisss.ColNo = (j+1);
|
orderBanciZuoweisss.RecStatus = "A";
|
orderBanciZuoweisss.Creater = string.IsNullOrEmpty(entity.Creater)? entity.Modifier : entity.Creater;
|
orderBanciZuoweisss.Createtime = DateTime.Now;
|
orderBanciZuoweisss.Modifier = orderBanciZuoweisss.Creater;
|
orderBanciZuoweisss.Modifytime = orderBanciZuoweisss.Createtime;
|
_context.OrderBanciZuoweis.Add(orderBanciZuoweisss);
|
}
|
}
|
}
|
|
//删除多余的座位
|
var orderBanciZuoweisdel = orderBanciZuoweis.Where(x => x.RowNo > entity.Hang.Value || x.ColNo > entity.Lie.Value).ToList();
|
if (orderBanciZuoweisdel != null && orderBanciZuoweisdel.Count > 0)
|
{
|
foreach (var orderBanciZuowei in orderBanciZuoweisdel)
|
{
|
orderBanciZuowei.RecStatus = "D";
|
}
|
}
|
|
|
}
|
else
|
{
|
//如果没有座位就删除所有座位
|
var orderBanciZuoweis = _context.OrderBanciZuoweis.Where(x => x.RecStatus == "A" && x.BanciId == entity.Id).ToList();
|
if(orderBanciZuoweis!=null && orderBanciZuoweis.Count > 0)
|
{
|
foreach ( var orderBanciZuowei in orderBanciZuoweis)
|
{
|
orderBanciZuowei.RecStatus = "D";
|
}
|
}
|
}
|
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = entity.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public OrderBanciDTO Get(string id)
|
{
|
|
var entity = _context.OrderBancis.Find(id);
|
|
if (entity.RecStatus != "A")
|
{
|
entity = new OrderBanci();
|
}
|
|
var result = _mapper.Map<OrderBanciDTO>(entity);
|
|
|
return result;
|
}
|
|
public OrderBanciDTO GetAll(string id)
|
{
|
|
var entity = _context.OrderBancis.Find(id);
|
|
|
|
var result = _mapper.Map<OrderBanciDTO>(entity);
|
|
|
return result;
|
}
|
|
public ResultDataEntity<OrderBanciDTO> SearchByPaging(OrderBanciDTOSearch searchEntity)
|
{
|
|
|
|
ResultDataEntity<OrderBanciDTO> data = new ResultDataEntity<OrderBanciDTO>();
|
List<OrderBanciDTO> list = new List<OrderBanciDTO>();
|
|
|
|
//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
|
// }
|
//);
|
|
///OrderBancis
|
///
|
DateTime Shijianstart = DateTime.Now;
|
DateTime Shijianend = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(searchEntity.Shijian))
|
{
|
string[] Shijians = searchEntity.Shijian.Split("|");
|
DateTime.TryParse(Shijians[0], out Shijianstart);
|
DateTime.TryParse(Shijians[1], out Shijianend);
|
Shijianend = Shijianend.AddDays(1);
|
}
|
|
var query = (from a in _context.OrderBancis
|
|
|
|
|
where a.RecStatus == "A"
|
|
&& (string.IsNullOrWhiteSpace(searchEntity.Banci) || a.Banci.Contains(searchEntity.Banci.Trim()))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Shijian) || (a.Shijian >= Shijianstart && a.Shijian <= Shijianend))
|
&& (string.IsNullOrWhiteSpace(searchEntity.Didian) || a.Didian.Contains(searchEntity.Didian.Trim()))
|
|
&& (string.IsNullOrWhiteSpace(searchEntity.Createtime) || a.Shijian >= DateTime.Parse(searchEntity.Createtime) )
|
|
|
|
|
select new OrderBanciDTO
|
{
|
Id = a.Id,
|
Banci = a.Banci,
|
Shijian = a.Shijian,
|
ShijianName = a.Shijian.HasValue? a.Shijian.Value.ToString("yyyy-MM-dd HH:mm"):"",
|
Didian = a.Didian,
|
Shijianend = a.Shijianend,
|
ShijianendName = a.Shijianend.HasValue ? a.Shijianend.Value.ToString("yyyy-MM-dd HH:mm") : "",
|
|
Mingcheng = a.Mingcheng,
|
|
Renshu = a.Renshu??0,
|
|
Hang = a.Hang ?? 0,
|
|
Lie = a.Lie ?? 0,
|
|
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
|
RecStatus = a.RecStatus,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
|
}
|
).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.OrderBancis.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<OrderBanciDTO> GetList()
|
{
|
|
|
var listRole = _context.OrderBancis.Where(r => r.RecStatus == "A").ToList();
|
|
|
var list = _mapper.Map<List<OrderBanciDTO>>(listRole);
|
return list;
|
}
|
|
|
|
public List<OrderBanciDTO> GetJifenBanciList()
|
{
|
|
|
|
ResultDataEntity<OrderBanciDTO> data = new ResultDataEntity<OrderBanciDTO>();
|
List<OrderBanciDTO> list = new List<OrderBanciDTO>();
|
|
|
|
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
|
}
|
);
|
|
///OrderBancis
|
///
|
|
|
var query = (from a in _context.OrderBancis
|
join b in _context.OrderBanciDtls on a.Id equals b.OrderBanciId
|
|
join d in listCode.Where(x => x.CodeTable == "order_banci_order" && x.CodeField == "kechengleixing_id")
|
on b.Shangxiawu equals d.CodeSn
|
into dzsssss
|
from dzzzzz in dzsssss.DefaultIfEmpty()
|
|
where a.RecStatus == "A" && b.RecStatus == "A" && b.Jifen != null
|
&& a.Shijianend >= DateTime.Now
|
|
|
|
|
|
|
select new OrderBanciDTO
|
{
|
img_url ="",
|
point = b.Jifen,
|
sell_price = b.Jiage,
|
type = "Train",
|
title = a.Mingcheng+"("+ dzzzzz.Comments+")",
|
Id = a.Id,
|
Banci = a.Banci,
|
Mingcheng = a.Mingcheng,
|
Shijian = a.Shijian,
|
ShijianName = a.Shijian.HasValue ? a.Shijian.Value.ToString("yyyy-MM-dd HH:mm") : "",
|
|
Shijianend = a.Shijianend,
|
ShijianendName = a.Shijianend.HasValue ? a.Shijianend.Value.ToString("yyyy-MM-dd HH:mm") : "",
|
|
Didian = a.Didian,
|
|
Renshu = a.Renshu ?? 0,
|
Hang = a.Hang ?? 0,
|
Lie = a.Lie ?? 0,
|
|
Creater = a.Creater,
|
Createtime = a.Createtime,
|
|
RecStatus = a.RecStatus,
|
Modifier = a.Modifier,
|
Modifytime = a.Modifytime,
|
|
|
Shangxiawu = b.Shangxiawu,
|
Shijiandtl = b.Shijian,
|
Shixiamg = b.Shixiamg,
|
Zhujiangren = b.Zhujiangren,
|
Sort = b.Sort,
|
ShangxiawuName = dzzzzz.Comments,
|
Jiage = b.Jiage,
|
Jifen = b.Jifen,
|
JiageName = b.Jiage.HasValue ? b.Jiage.Value.ToString() : "",
|
JifenName = b.Jifen.HasValue ? b.Jifen.Value.ToString() : "",
|
id = a.Id,
|
|
}
|
).OrderByDescending(x => x.Shijian).ThenBy(x=>x.Sort).ToList();
|
|
|
|
return query;
|
}
|
|
|
public ResultEntity saveZuowei(OrderBanciZuoweiDTO dto)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
try
|
{
|
|
|
var entity = _mapper.Map<OrderBanciZuowei>(dto);
|
|
|
if (String.IsNullOrEmpty(entity.Id))
|
{
|
entity.Id = Guid.NewGuid().ToString();
|
dto.Id = entity.Id;
|
_context.OrderBanciZuoweis.Add(entity);
|
}
|
else
|
{
|
var updateproject = _context.OrderBanciZuoweis.Find(entity.Id);
|
|
updateproject.BanciId = entity.BanciId;
|
updateproject.ZuoweiId = entity.ZuoweiId;
|
|
updateproject.SeatNo = entity.SeatNo;
|
updateproject.Status = entity.Status;
|
|
updateproject.RowNo = entity.RowNo;
|
updateproject.ColNo = entity.ColNo;
|
|
updateproject.RecStatus = entity.RecStatus;
|
updateproject.Modifier = entity.Modifier;
|
updateproject.Modifytime = entity.Modifytime;
|
|
}
|
|
_context.SaveChanges();
|
resultEntity.ReturnID = entity.Id;
|
resultEntity.Result = true;
|
}
|
catch (Exception ex)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "保存失败,请联系管理员";
|
|
}
|
return resultEntity;
|
}
|
|
public List<OrderBanciZuoweiDTO> GetOrderBanciZuoweiList(string banciId)
|
{
|
var listRole = _context.OrderBanciZuoweis.Where(r => r.RecStatus == "A" && r.BanciId == banciId).OrderBy(x=>x.RowNo).ThenBy(x=>x.ColNo).ToList();
|
|
|
var list = _mapper.Map<List<OrderBanciZuoweiDTO>>(listRole);
|
|
return list;
|
}
|
}
|
}
|