452 lines
17 KiB
C#
452 lines
17 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using Microsoft.CodeAnalysis.Elfie.Model.Tree;
|
|||
|
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
using SupplierManager.Common;
|
|||
|
|
using SupplierManager.Models;
|
|||
|
|
using ViewModels;
|
|||
|
|
|
|||
|
|
namespace SupplierManager.Controllers
|
|||
|
|
{
|
|||
|
|
[Route("api/[controller]/[action]")]
|
|||
|
|
[ApiController]
|
|||
|
|
public class AasProjectInfoesController : ControllerBase
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
// GET: api/AasProjectInfoes
|
|||
|
|
[HttpPost()]
|
|||
|
|
[Authorize()]
|
|||
|
|
public async Task<ReturnInfo> GetAasProjectInfos([FromBody] QueryAll_Or_Single_ProjectInfo S)
|
|||
|
|
{
|
|||
|
|
ReturnInfo returnInfo = new ReturnInfo();
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (var q = new AgentApprovalSystemContext())
|
|||
|
|
{
|
|||
|
|
if (S.IsAll)
|
|||
|
|
{
|
|||
|
|
returnInfo.isok = true;
|
|||
|
|
var U = q.AasProjectInfos.Where(A => A.CompanyId == S.ComId).ToList();
|
|||
|
|
|
|||
|
|
var A = new List<ShengPiDDD>();
|
|||
|
|
foreach (AasProjectInfo item in U)
|
|||
|
|
{
|
|||
|
|
ShengPiDDD s = new ShengPiDDD();
|
|||
|
|
s.Id = item.Id;
|
|||
|
|
s.Shengfen = item.Shengfen;
|
|||
|
|
s.Quyu = item.Quyu;
|
|||
|
|
s.AddressDetail = item.AddressDetail;
|
|||
|
|
s.HangyeClass = item.HangyeClass;
|
|||
|
|
s.ProjectCode = item.ProjectCode;
|
|||
|
|
s.ProjectName = item.ProjectName;
|
|||
|
|
s.CompanyId = item.CompanyId;
|
|||
|
|
s.RoomTotalCount = item.RoomTotalCount;
|
|||
|
|
s.RoomTypeCount = item.RoomTypeCount;
|
|||
|
|
s.Blueprint = item.Blueprint;
|
|||
|
|
s.Createtime = item.Createtime;
|
|||
|
|
s.Updatetime = item.Updatetime;
|
|||
|
|
s.ShengpiStatus = item.ShengpiStatus;
|
|||
|
|
s.Uid = item.Uid;
|
|||
|
|
s.Customization = item.Customization;
|
|||
|
|
|
|||
|
|
var U1 = q.AasProjectShenpis.Where(A => A.ProjectCode == item.ProjectCode).ToList();
|
|||
|
|
s.sp = U1;
|
|||
|
|
A.Add(s);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//var query = from t1 in q.AasProjectInfos
|
|||
|
|
// join t2 in q.AasProjectShenpis on t1.ProjectCode equals t2.ProjectCode into tt1
|
|||
|
|
// from t3 in tt1.DefaultIfEmpty()
|
|||
|
|
// where t1.CompanyId == S.ComId
|
|||
|
|
// select new
|
|||
|
|
// {
|
|||
|
|
// t1.Id,
|
|||
|
|
// t1.Shengfen,
|
|||
|
|
// t1.Quyu,
|
|||
|
|
// t1.AddressDetail,
|
|||
|
|
// t1.HangyeClass,
|
|||
|
|
// t1.ProjectName,
|
|||
|
|
// t1.ProjectCode,
|
|||
|
|
// t1.CompanyId,
|
|||
|
|
// t1.RoomTotalCount,
|
|||
|
|
// t1.RoomTypeCount,
|
|||
|
|
// t3.RejectReason,
|
|||
|
|
// t3.ShenpiNumber,
|
|||
|
|
// sp_Createtime= t3.Createtime
|
|||
|
|
// };
|
|||
|
|
|
|||
|
|
//var result = query.ToList();
|
|||
|
|
//var D = Q.ToList<ShengPiDDD>();
|
|||
|
|
//var D = Q.ToList();
|
|||
|
|
returnInfo.response = A;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//returnInfo.isok = true;
|
|||
|
|
//var a = q.AasUsers.SingleOrDefault(A => A.Id == S.ID);
|
|||
|
|
//if (a != null)
|
|||
|
|
//{
|
|||
|
|
// returnInfo.response = a;
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
returnInfo.isok = false;
|
|||
|
|
returnInfo.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
return returnInfo;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
[HttpPost()]
|
|||
|
|
[Authorize()]
|
|||
|
|
public async Task<ReturnInfo> GetAasProjectInfos_Page([FromBody] QueryAll_Or_Single_ProjectInfo_Page S)
|
|||
|
|
{
|
|||
|
|
ReturnInfo returnInfo = new ReturnInfo();
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
DateTime dt_s = DateTime.Now;
|
|||
|
|
|
|||
|
|
DateTime dt_e = DateTime.Now;
|
|||
|
|
|
|||
|
|
using var q = new AgentApprovalSystemContext();
|
|||
|
|
|
|||
|
|
|
|||
|
|
List<AasProjectInfo> U = new List<AasProjectInfo>();
|
|||
|
|
if (!string.IsNullOrEmpty(S.UpdateTime_Start) && !string.IsNullOrEmpty(S.UpdateTime_End) && S.ComId != 0)
|
|||
|
|
{
|
|||
|
|
DateTime.TryParse(S.UpdateTime_Start, out dt_s);
|
|||
|
|
DateTime.TryParse(S.UpdateTime_End, out dt_e);
|
|||
|
|
long dt_s_l = Tools.ToUnixTimestampBySeconds(dt_s);
|
|||
|
|
long dt_e_l = Tools.ToUnixTimestampBySeconds(dt_e);
|
|||
|
|
U = await q.AasProjectInfos.Where(A => A.CompanyId == S.ComId && A.UpdatetimeUnix > dt_s_l && A.UpdatetimeUnix <= dt_e_l).ToListAsync();
|
|||
|
|
}
|
|||
|
|
else if (string.IsNullOrEmpty(S.UpdateTime_Start) && string.IsNullOrEmpty(S.UpdateTime_End) && S.ComId != 0)
|
|||
|
|
{
|
|||
|
|
U = await q.AasProjectInfos.Where(A => A.CompanyId == S.ComId).ToListAsync();
|
|||
|
|
}
|
|||
|
|
else if (!string.IsNullOrEmpty(S.UpdateTime_Start) && !string.IsNullOrEmpty(S.UpdateTime_End) && S.ComId == 0)
|
|||
|
|
{
|
|||
|
|
DateTime.TryParse(S.UpdateTime_Start, out dt_s);
|
|||
|
|
DateTime.TryParse(S.UpdateTime_End, out dt_e);
|
|||
|
|
long dt_s_l = Tools.ToUnixTimestampBySeconds(dt_s);
|
|||
|
|
long dt_e_l = Tools.ToUnixTimestampBySeconds(dt_e);
|
|||
|
|
U = await q.AasProjectInfos.Where(A => A.UpdatetimeUnix > dt_s_l && A.UpdatetimeUnix <= dt_e_l).ToListAsync();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
var A = new List<ShengPiDDD>();
|
|||
|
|
foreach (AasProjectInfo item in U)
|
|||
|
|
{
|
|||
|
|
ShengPiDDD s = new ShengPiDDD();
|
|||
|
|
s.Id = item.Id;
|
|||
|
|
s.Shengfen = item.Shengfen;
|
|||
|
|
s.Quyu = item.Quyu;
|
|||
|
|
s.AddressDetail = item.AddressDetail;
|
|||
|
|
s.HangyeClass = item.HangyeClass;
|
|||
|
|
s.ProjectCode = item.ProjectCode;
|
|||
|
|
s.ProjectName = item.ProjectName;
|
|||
|
|
s.CompanyId = item.CompanyId;
|
|||
|
|
s.RoomTotalCount = item.RoomTotalCount;
|
|||
|
|
s.RoomTypeCount = item.RoomTypeCount;
|
|||
|
|
s.Blueprint = item.Blueprint;
|
|||
|
|
s.Createtime = item.Createtime;
|
|||
|
|
s.Updatetime = item.Updatetime;
|
|||
|
|
s.ShengpiStatus = item.ShengpiStatus;
|
|||
|
|
s.Uid = item.Uid;
|
|||
|
|
s.Customization = item.Customization;
|
|||
|
|
|
|||
|
|
var U1 = await q.AasProjectShenpis.Where(A => A.ProjectCode == item.ProjectCode).ToListAsync();
|
|||
|
|
s.sp = U1;
|
|||
|
|
A.Add(s);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
returnInfo.isok = true;
|
|||
|
|
returnInfo.response = A;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
returnInfo.isok = false;
|
|||
|
|
returnInfo.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
return returnInfo;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public class ShengPiDDD : AasProjectInfo
|
|||
|
|
{
|
|||
|
|
public List<AasProjectShenpi> sp { get; set; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class PInfo
|
|||
|
|
{
|
|||
|
|
public long id { get; set; }
|
|||
|
|
public string projectName { get; set; }
|
|||
|
|
public int projectCode { get; set; }
|
|||
|
|
public string shengfen { get; set; }
|
|||
|
|
public string quyu { get; set; }
|
|||
|
|
public string? addressDetail { get; set; }
|
|||
|
|
public string? hangyeClass { get; set; }
|
|||
|
|
public int roomTypeCount { get; set; }
|
|||
|
|
public int roomTotalCount { get; set; }
|
|||
|
|
public string? blueprint { get; set; }
|
|||
|
|
public string? customization { get; set; }
|
|||
|
|
}
|
|||
|
|
// PUT: api/AasProjectInfoes/5
|
|||
|
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|||
|
|
[HttpPost()]
|
|||
|
|
[Authorize()]
|
|||
|
|
public async Task<ReturnInfo> EditProjectInfo([FromBody] PInfo record)
|
|||
|
|
{
|
|||
|
|
ReturnInfo r = new ReturnInfo();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using var _context = new AgentApprovalSystemContext();
|
|||
|
|
var aasProjectInfo = _context.AasProjectInfos.SingleOrDefault(A => A.Id == record.id);
|
|||
|
|
if (aasProjectInfo != null)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
DateTime dt = DateTime.Now;
|
|||
|
|
aasProjectInfo.Updatetime = dt;
|
|||
|
|
aasProjectInfo.UpdatetimeUnix = Tools.ToUnixTimestampBySeconds(dt);
|
|||
|
|
aasProjectInfo.Shengfen = record.shengfen;
|
|||
|
|
aasProjectInfo.ProjectName = record.projectName;
|
|||
|
|
aasProjectInfo.Quyu = record.quyu;
|
|||
|
|
aasProjectInfo.AddressDetail = record.addressDetail;
|
|||
|
|
aasProjectInfo.RoomTotalCount = record.roomTotalCount;
|
|||
|
|
aasProjectInfo.RoomTypeCount = record.roomTypeCount;
|
|||
|
|
aasProjectInfo.HangyeClass = record.hangyeClass;
|
|||
|
|
aasProjectInfo.Blueprint = record.blueprint;
|
|||
|
|
aasProjectInfo.Customization = record.customization;
|
|||
|
|
|
|||
|
|
_context.Entry(aasProjectInfo).State = EntityState.Modified;
|
|||
|
|
await _context.SaveChangesAsync();
|
|||
|
|
r.isok = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = "你修改了一个不存在的数据,这是不允许的";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
return r;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// POST: api/AasProjectInfoes
|
|||
|
|
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
|||
|
|
[HttpPost]
|
|||
|
|
[Authorize()]
|
|||
|
|
public async Task<ReturnInfo> AddAasProjectInfo(AasProjectInfo aasProjectInfo)
|
|||
|
|
{
|
|||
|
|
ReturnInfo r = new ReturnInfo();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
lock (StaticData.obj)
|
|||
|
|
{
|
|||
|
|
using (var _context = new AgentApprovalSystemContext())
|
|||
|
|
{
|
|||
|
|
using var tran = _context.Database.BeginTransaction();
|
|||
|
|
var QQQ = _context.Autokeygeneraters.SingleOrDefault();
|
|||
|
|
if (QQQ != null)
|
|||
|
|
{
|
|||
|
|
long? n = QQQ.ProjectInfoCode + 1;
|
|||
|
|
QQQ.ProjectInfoCode = n;
|
|||
|
|
_context.Autokeygeneraters.Update(QQQ);
|
|||
|
|
aasProjectInfo.ProjectCode = n.ToString();
|
|||
|
|
}
|
|||
|
|
long ll = Tools.ToUnixTimestampBySeconds(DateTime.Now);
|
|||
|
|
aasProjectInfo.Createtime = DateTime.Now;
|
|||
|
|
aasProjectInfo.Updatetime = DateTime.Now;
|
|||
|
|
aasProjectInfo.ShengpiStatus = "1";
|
|||
|
|
aasProjectInfo.CreatetimeUnix = ll;
|
|||
|
|
aasProjectInfo.UpdatetimeUnix = ll;
|
|||
|
|
_context.AasProjectInfos.Add(aasProjectInfo);
|
|||
|
|
_context.SaveChanges();
|
|||
|
|
|
|||
|
|
tran.Commit();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
r.isok = true;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
return r;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DELETE: api/AasProjectInfoes/5
|
|||
|
|
[HttpPost()]
|
|||
|
|
[Authorize()]
|
|||
|
|
public async Task<ReturnInfo> DeleteAasProjectInfo(long id)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
ReturnInfo r = new ReturnInfo();
|
|||
|
|
r.isok = true;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
using var _context = new AgentApprovalSystemContext();
|
|||
|
|
|
|||
|
|
var aasProjectInfo = await _context.AasProjectInfos.FindAsync(id);
|
|||
|
|
if (aasProjectInfo == null)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = "要删除的数据不存在";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_context.AasProjectInfos.Remove(aasProjectInfo);
|
|||
|
|
await _context.SaveChangesAsync();
|
|||
|
|
r.isok = true;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
[HttpPost()]
|
|||
|
|
[Authorize()]
|
|||
|
|
public async Task<ReturnInfo> StatusChange_AasProjectInfo([FromBody] A a)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
ReturnInfo r = new ReturnInfo();
|
|||
|
|
r.isok = true;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
using var _context = new AgentApprovalSystemContext();
|
|||
|
|
|
|||
|
|
|
|||
|
|
var aasProjectInfo = await _context.AasProjectInfos.FindAsync(a.id);
|
|||
|
|
if (aasProjectInfo == null)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = "要修改的数据不存在";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (a.Status.Equals("3"))
|
|||
|
|
{
|
|||
|
|
var aasProjectInfo0 = await _context.AasProjectInfos.Where(X => X.ShengpiStatus.Equals("3") && X.ProjectName.Equals(aasProjectInfo.ProjectName)).ToListAsync();
|
|||
|
|
if (aasProjectInfo0.Count > 0)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = "已有同名项目,请重试";
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
aasProjectInfo.ShengpiStatus = a.Status;
|
|||
|
|
aasProjectInfo.Updatetime = DateTime.Now;
|
|||
|
|
_context.AasProjectInfos.Update(aasProjectInfo);
|
|||
|
|
await _context.SaveChangesAsync();
|
|||
|
|
r.isok = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpPost()]
|
|||
|
|
[Authorize()]
|
|||
|
|
public async Task<ReturnInfo> Get_ProjectCode_Generate()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
ReturnInfo r = new ReturnInfo();
|
|||
|
|
r.isok = true;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using var _context = new AgentApprovalSystemContext();
|
|||
|
|
var a = await _context.Autokeygeneraters.FirstOrDefaultAsync();
|
|||
|
|
if (a == null)
|
|||
|
|
{
|
|||
|
|
Autokeygenerater d1 = new Autokeygenerater();
|
|||
|
|
d1.ProjectInfoCode = 1000;
|
|||
|
|
_context.Autokeygeneraters.Add(d1);
|
|||
|
|
r.isok = true;
|
|||
|
|
r.response = a.ProjectInfoCode;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
a.ProjectInfoCode = a.ProjectInfoCode + 1;
|
|||
|
|
_context.Autokeygeneraters.Update(a);
|
|||
|
|
r.isok = true;
|
|||
|
|
r.response = a.ProjectInfoCode;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
await _context.SaveChangesAsync();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
[HttpPost()]
|
|||
|
|
[Authorize()]
|
|||
|
|
public async Task<ReturnInfo> Get_ProjectByStatusCode()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
ReturnInfo r = new ReturnInfo();
|
|||
|
|
r.isok = true;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using var _context = new AgentApprovalSystemContext();
|
|||
|
|
var LLL = await _context.AasProjectInfos.Where(A => A.ShengpiStatus.Equals("3")).ToListAsync();
|
|||
|
|
r.response = LLL;
|
|||
|
|
r.isok = true;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
r.isok = false;
|
|||
|
|
r.message = ex.Message;
|
|||
|
|
}
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public class A
|
|||
|
|
{
|
|||
|
|
public long id { get; set; }
|
|||
|
|
public string? Status { get; set; }
|
|||
|
|
//public string? Name { get; set; }
|
|||
|
|
}
|
|||
|
|
}
|