初始化
This commit is contained in:
120
SupplierManager/Controllers/AasCustomerInfoesController.cs
Normal file
120
SupplierManager/Controllers/AasCustomerInfoesController.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SupplierManager.Models;
|
||||
using ViewModels;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class AasCustomerInfoesController : ControllerBase
|
||||
{
|
||||
private readonly AgentApprovalSystemContext _context;
|
||||
|
||||
public AasCustomerInfoesController(AgentApprovalSystemContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/AasCustomerInfoes
|
||||
[HttpGet]
|
||||
public async Task<ReturnInfo> GetAasCustomerInfos([FromBody] QueryAll_Or_Single S)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
returnInfo.isok = true;
|
||||
if (S.IsAll)
|
||||
{
|
||||
returnInfo.response = await _context.AasCustomerInfos.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var aasCustomerInfo = await _context.AasCustomerInfos.FindAsync(S.ID);
|
||||
|
||||
returnInfo.response = aasCustomerInfo;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
|
||||
// PUT: api/AasCustomerInfoes/5
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[HttpPut("{id}")]
|
||||
public async Task<ReturnInfo> PutAasCustomerInfo([FromBody] AasCustomerInfo aasCustomerInfo)
|
||||
{
|
||||
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
_context.Entry(aasCustomerInfo).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// POST: api/AasCustomerInfoes
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[HttpPost]
|
||||
public async Task<ReturnInfo> AddAasCustomerInfo([FromBody] AasCustomerInfo aasCustomerInfo)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
_context.AasCustomerInfos.Add(aasCustomerInfo);
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
public async Task<ReturnInfo> DeleteAasCustomerInfo([FromBody] Dictionary<string, long> stu)
|
||||
{
|
||||
ReturnInfo re = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
|
||||
long id = stu["id"];
|
||||
re.isok = true;
|
||||
var aasCustomerInfo = await _context.AasCustomerInfos.FindAsync(id);
|
||||
|
||||
if (aasCustomerInfo != null)
|
||||
{
|
||||
_context.AasCustomerInfos.Remove(aasCustomerInfo);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
re.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
re.isok = false;
|
||||
}
|
||||
return re;
|
||||
}
|
||||
}
|
||||
}
|
||||
451
SupplierManager/Controllers/AasProjectInfoesController.cs
Normal file
451
SupplierManager/Controllers/AasProjectInfoesController.cs
Normal file
@@ -0,0 +1,451 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
129
SupplierManager/Controllers/AasProjectReportReadiesController.cs
Normal file
129
SupplierManager/Controllers/AasProjectReportReadiesController.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SupplierManager.Models;
|
||||
using ViewModels;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class AasProjectReportReadiesController : ControllerBase
|
||||
{
|
||||
private readonly AgentApprovalSystemContext _context;
|
||||
|
||||
public AasProjectReportReadiesController(AgentApprovalSystemContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/AasProjectReportReadies
|
||||
[HttpPost()]
|
||||
public async Task<ReturnInfo> GetAasProjectReportReadies([FromBody] QueryAll_Or_Single_ProjectInfo S)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
if (S.IsAll)
|
||||
{
|
||||
|
||||
returnInfo.isok = true;
|
||||
returnInfo.response = await _context.AasProjectReportReadies.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
returnInfo.isok = true;
|
||||
var a = await _context.AasProjectReportReadies.FindAsync(S.ID);
|
||||
if (a != null)
|
||||
{
|
||||
returnInfo.response = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
|
||||
// PUT: api/AasProjectReportReadies/5
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[HttpPost()]
|
||||
public async Task<ReturnInfo> EditAasProjectReportReady(AasProjectReportReady aasProjectReportReady)
|
||||
{
|
||||
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
_context.Entry(aasProjectReportReady).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// POST: api/AasProjectReportReadies
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[HttpPost]
|
||||
public async Task<ReturnInfo> AddAasProjectReportReady(AasProjectReportReady aasProjectReportReady)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
|
||||
_context.AasProjectReportReadies.Add(aasProjectReportReady);
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// DELETE: api/AasProjectReportReadies/5
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ReturnInfo> DeleteAasProjectReportReady(long id)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
var aasProjectReportReady = await _context.AasProjectReportReadies.FindAsync(id);
|
||||
if (aasProjectReportReady == null)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = "找不到要删除的数据";
|
||||
}
|
||||
|
||||
_context.AasProjectReportReadies.Remove(aasProjectReportReady);
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
139
SupplierManager/Controllers/AasProjectShenpisController.cs
Normal file
139
SupplierManager/Controllers/AasProjectShenpisController.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
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.EntityFrameworkCore;
|
||||
using SupplierManager.Models;
|
||||
using ViewModels;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class AasProjectShenpisController : ControllerBase
|
||||
{
|
||||
private readonly AgentApprovalSystemContext _context;
|
||||
|
||||
public AasProjectShenpisController(AgentApprovalSystemContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/AasProjectShenpis
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public async Task<ReturnInfo> GetAasProjectShenpis([FromBody] QueryAll_Or_Single_ProjectInfo S)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
if (S.IsAll)
|
||||
{
|
||||
r.response = await _context.AasProjectShenpis.ToListAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var aasProjectShenpi = await _context.AasProjectShenpis.FindAsync(S.ID);
|
||||
r.isok = true;
|
||||
r.response = aasProjectShenpi;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public async Task<ReturnInfo> EditAasProjectShenpi([FromBody] AasProjectShenpi aasProjectShenpi)
|
||||
{
|
||||
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
aasProjectShenpi.Updatetime = DateTime.Now;
|
||||
_context.Entry(aasProjectShenpi).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public async Task<ReturnInfo> AddAasProjectShenpi(AasProjectShenpi aasProjectShenpi)
|
||||
{
|
||||
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
r.isok = false;
|
||||
try
|
||||
{
|
||||
var Q = _context.AasProjectShenpis.Where(x => x.ProjectCode.Equals(aasProjectShenpi.ProjectCode));
|
||||
if (Q.Count() > 0)
|
||||
{
|
||||
var Q1 = Q.OrderByDescending(A => A.ShenpiNumber).FirstOrDefault();
|
||||
aasProjectShenpi.ShenpiNumber = Q1?.ShenpiNumber + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
aasProjectShenpi.ShenpiNumber = 0;
|
||||
}
|
||||
aasProjectShenpi.Updatetime = DateTime.Now;
|
||||
_context.AasProjectShenpis.Add(aasProjectShenpi);
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// DELETE: api/AasProjectShenpis/5
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public async Task<ReturnInfo> DeleteAasProjectShenpi(long id)
|
||||
{
|
||||
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
|
||||
var aasProjectShenpi = await _context.AasProjectShenpis.FindAsync(id);
|
||||
if (aasProjectShenpi == null)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = "找不到相应的数据";
|
||||
}
|
||||
_context.AasProjectShenpis.Remove(aasProjectShenpi);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
private bool AasProjectShenpiExists(long id)
|
||||
{
|
||||
return _context.AasProjectShenpis.Any(e => e.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
235
SupplierManager/Controllers/CompanyController.cs
Normal file
235
SupplierManager/Controllers/CompanyController.cs
Normal file
@@ -0,0 +1,235 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SupplierManager.Models;
|
||||
using ViewModels;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class CompanyController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="LLL"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo DelCom([FromBody] Dictionary<string, int> LLL)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
int idd = LLL["Id"];
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
var FFF = q.AasCompanyInfos.FirstOrDefault(A => A.Id == idd);
|
||||
if (FFF != null)
|
||||
{
|
||||
q.AasCompanyInfos.Remove(FFF);
|
||||
q.SaveChanges();
|
||||
returnInfo.isok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
/// <param name="LLL"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo EditCom([FromBody] Com LLL)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
var lll = q.AasCompanyInfos.SingleOrDefault(A => A.Id == LLL.Id);
|
||||
if (lll != null)
|
||||
{
|
||||
|
||||
lll.NameCn = LLL.NameCn;
|
||||
lll.NameEn = LLL.NameEn;
|
||||
lll.Identity = LLL.Identity;
|
||||
lll.Industry = LLL.Industry;
|
||||
lll.Code = LLL.Code;
|
||||
lll.LicenseCode = LLL.LicenseCode;
|
||||
lll.Region = LLL.Region;
|
||||
lll.Logoaddress= LLL.Logoaddress;
|
||||
lll.Updatetime = DateTime.Now;
|
||||
|
||||
q.AasCompanyInfos.Update(lll);
|
||||
q.SaveChanges();
|
||||
returnInfo.isok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户信息
|
||||
/// </summary>
|
||||
/// <param name="S"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo GetComInfo([FromBody] QueryAll_Or_Single S)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
if (S.IsAll)
|
||||
{
|
||||
returnInfo.isok = true;
|
||||
returnInfo.response = q.AasCompanyInfos.Select(F => new AasCompanyInfo
|
||||
{
|
||||
Id = F.Id,
|
||||
Code = F.Code,
|
||||
NameCn = F.NameCn,
|
||||
NameEn = F.NameEn,
|
||||
Identity = F.Identity,
|
||||
LicenseCode = F.LicenseCode,
|
||||
Industry = F.Industry,
|
||||
Region = F.Region,
|
||||
Logoaddress = F.Logoaddress
|
||||
}).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
returnInfo.isok = true;
|
||||
var a = q.AasCompanyInfos.SingleOrDefault(A => A.Id == S.ID);
|
||||
if (a != null)
|
||||
{
|
||||
AasCompanyInfo u = new AasCompanyInfo();
|
||||
u.Id = a.Id;
|
||||
u.Code = a.Code;
|
||||
u.NameCn = a.NameCn;
|
||||
u.NameEn = a.NameEn;
|
||||
u.Updatetime = a.Updatetime;
|
||||
u.Createtime = a.Createtime;
|
||||
u.Industry = a.Industry;
|
||||
u.LicenseCode = a.LicenseCode;
|
||||
u.Region = a.Region;
|
||||
returnInfo.response = u;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户
|
||||
/// </summary>
|
||||
/// <param name="LLL"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo AddCom([FromBody] Com LLL)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
AasCompanyInfo a = new AasCompanyInfo();
|
||||
a.NameCn = LLL.NameCn;
|
||||
a.NameEn = LLL.NameEn;
|
||||
a.Identity = LLL.Identity;
|
||||
a.Industry = LLL.Industry;
|
||||
a.Region = LLL.Region;
|
||||
a.Logoaddress = LLL.Logoaddress;
|
||||
a.Createtime = DateTime.Now;
|
||||
a.Updatetime = DateTime.Now;
|
||||
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
var Q = q.AasCompanyInfos.Where(A => A.NameCn.Equals(LLL.NameCn));
|
||||
if (Q.Count() > 0)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = "此公司已经存在";
|
||||
}
|
||||
else
|
||||
{
|
||||
using var T = q.Database.BeginTransaction();
|
||||
Autokeygenerater? QQQ = q.Autokeygeneraters.SingleOrDefault();
|
||||
QQQ.CompanyCode = QQQ.CompanyCode + 1;
|
||||
|
||||
a.Code = QQQ.CompanyCode.ToString();
|
||||
q.Autokeygeneraters.Update(QQQ);
|
||||
q.AasCompanyInfos.Add(a);
|
||||
returnInfo.isok = true;
|
||||
q.SaveChanges();
|
||||
T.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
}
|
||||
public class Com
|
||||
{
|
||||
|
||||
public int Id { get; set; } = -1;
|
||||
public string? Code { get; set; }
|
||||
|
||||
public string? NameCn { get; set; }
|
||||
|
||||
public string? NameEn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属行业
|
||||
/// </summary>
|
||||
public string? Industry { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 身份
|
||||
/// </summary>
|
||||
public string? Identity { get; set; }
|
||||
|
||||
public string? Region { get; set; }
|
||||
public string? Logoaddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业执照
|
||||
/// </summary>
|
||||
public string? LicenseCode { get; set; }
|
||||
}
|
||||
}
|
||||
134
SupplierManager/Controllers/ConfigPYController.cs
Normal file
134
SupplierManager/Controllers/ConfigPYController.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Scripting.Utils;
|
||||
using SupplierManager.Common;
|
||||
using ViewModels;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ConfigPYController : ControllerBase
|
||||
{
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public async Task<ReturnInfo> GetConfigString()
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
string[] str = await System.IO.File.ReadAllLinesAsync("script\\webapi.py");
|
||||
|
||||
List<VK> ll = new List<VK>();
|
||||
foreach (var item in str)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(item))
|
||||
{
|
||||
string[] a = item.Split('=');
|
||||
VK v = new VK();
|
||||
v.VarName = a[0];
|
||||
v.VarValue = a[1];
|
||||
ll.Add(v);
|
||||
}
|
||||
}
|
||||
|
||||
r.isok = true;
|
||||
r.response = ll;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo RefreshConfig()
|
||||
{
|
||||
ReturnInfo info = new ReturnInfo();
|
||||
info.isok = true;
|
||||
try
|
||||
{
|
||||
StaticData.GetWebAPIMethod();
|
||||
info.message = "Sucess";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
info.isok = false;
|
||||
info.message = ex.Message;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public class VK
|
||||
{
|
||||
public string VarName { get; set; }
|
||||
public string VarValue { get; set; }
|
||||
}
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public async Task<ReturnInfo> SaveOrAddConfigString([FromBody] VK data)
|
||||
{
|
||||
ReturnInfo info = new ReturnInfo();
|
||||
info.isok = true;
|
||||
try
|
||||
{
|
||||
var sss = System.IO.File.ReadAllLines("script\\webapi.py", Encoding.UTF8).ToList<string>();
|
||||
for (int i = 0; i < sss.Count; i++)
|
||||
{
|
||||
string item = sss[i];
|
||||
string[] txtdata = item.Split('=');
|
||||
if (txtdata[0].Equals(data.VarName))
|
||||
{
|
||||
txtdata[1] = data.VarValue;
|
||||
sss[i] = txtdata[0] + "=" + txtdata[1];
|
||||
}
|
||||
}
|
||||
bool exists = sss.Any(A => A.StartsWith(data.VarName));
|
||||
|
||||
if (exists == false)
|
||||
{
|
||||
sss.AddRange<string>(new string[] { data.VarName + "=" + data.VarValue });
|
||||
}
|
||||
|
||||
await System.IO.File.WriteAllLinesAsync("script\\webapi.py", sss, Encoding.UTF8);
|
||||
StaticData.GetWebAPIMethod();
|
||||
info.message = "Sucess";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
info.isok = false;
|
||||
info.message = ex.Message;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo GetSingleValue([FromBody] Dictionary<string, string> dic)
|
||||
{
|
||||
ReturnInfo info = new ReturnInfo();
|
||||
info.isok = true;
|
||||
try
|
||||
{
|
||||
string VarValue = dic["VarName"];
|
||||
if (!string.IsNullOrEmpty(VarValue))
|
||||
{
|
||||
var QQQ = StaticData.scope1.GetVariable(VarValue);
|
||||
string str = System.Text.Json.JsonSerializer.Serialize(QQQ);
|
||||
info.response = str;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
info.isok = false;
|
||||
info.message = ex.Message;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
134
SupplierManager/Controllers/FileUploadController.cs
Normal file
134
SupplierManager/Controllers/FileUploadController.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class FileUploadController : ControllerBase
|
||||
{
|
||||
|
||||
public static string[] FolderG = new string[] {"face" };
|
||||
|
||||
[Authorize()]
|
||||
[HttpPost()]
|
||||
public async Task<IActionResult> UploadFile([FromForm] UploadFileModel model)
|
||||
{
|
||||
if (model.File == null || model.File.Length == 0)
|
||||
{
|
||||
return BadRequest("没有上传任何文件");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 获取文件名和扩展名
|
||||
string originalFileName = Path.GetFileNameWithoutExtension(model.File.FileName);
|
||||
string fileExtension = Path.GetExtension(model.File.FileName); // 包含扩展名前的点(如.jpg)
|
||||
|
||||
// 生成8位GUID(取完整GUID的前8位字符)
|
||||
string guidPart = Guid.NewGuid().ToString("N")[..16];
|
||||
|
||||
// 组合新文件名:原文件名_8位GUID.扩展名
|
||||
string newFileName = $"{originalFileName}_{guidPart}{fileExtension}";
|
||||
|
||||
var filePath = Path.Combine(Directory.GetCurrentDirectory(),
|
||||
$"wwwroot/Uploads/{model.Folder}",
|
||||
newFileName);
|
||||
|
||||
using (var stream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
await model.File.CopyToAsync(stream);
|
||||
}
|
||||
return Ok(new { FileName = newFileName });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(new { Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public record DF
|
||||
{
|
||||
public string? FileName { get; set; }
|
||||
}
|
||||
// 示例:通过文件名获取图片
|
||||
[Authorize()]
|
||||
[HttpPost()]
|
||||
public IActionResult DownloadFile([FromBody]DF imageName)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 拼接图片物理路径(假设图片存放在项目的 wwwroot/images 目录下)
|
||||
var imagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/", imageName.FileName);
|
||||
|
||||
// 检查文件是否存在
|
||||
if (!System.IO.File.Exists(imagePath))
|
||||
{
|
||||
return NotFound("Image not found");
|
||||
}
|
||||
if (imageName.FileName.Contains(".."))
|
||||
{
|
||||
return BadRequest("Invalid file name");
|
||||
}
|
||||
|
||||
|
||||
// 读取文件流并返回
|
||||
var imageStream = System.IO.File.OpenRead(imagePath);
|
||||
|
||||
// 根据扩展名自动设置 Content-Type(MIME类型)
|
||||
var mimeType = GetMimeType(imageName.FileName);
|
||||
|
||||
return File(imageStream, mimeType);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Internal server error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize()]
|
||||
[HttpPost()]
|
||||
public IActionResult GetFileNameList()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 拼接图片物理路径(假设图片存放在项目的 wwwroot/images 目录下)
|
||||
var filePath = Path.Combine(Directory.GetCurrentDirectory(),
|
||||
$"wwwroot/Download/customization","");
|
||||
|
||||
string[] files= System.IO.Directory.GetFiles(filePath);
|
||||
var myfiles= files.Select(A=>Path.GetFileName(A));
|
||||
return Ok(new { FileNameList = myfiles });
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Internal server error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取 MIME 类型映射
|
||||
private string GetMimeType(string fileName)
|
||||
{
|
||||
var extension = Path.GetExtension(fileName).ToLowerInvariant();
|
||||
return
|
||||
extension switch
|
||||
{
|
||||
".jpg" => "image/jpeg",
|
||||
".jpeg" => "image/jpeg",
|
||||
".png" => "image/png",
|
||||
".gif" => "image/gif",
|
||||
".xls" =>"application/vnd.ms-excel",
|
||||
".xlsx"=>"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
_ => "application/octet-stream" // 默认类型
|
||||
};
|
||||
}
|
||||
}
|
||||
public class UploadFileModel
|
||||
{
|
||||
public IFormFile File { get; set; }
|
||||
public string Folder { get; set; }
|
||||
}
|
||||
}
|
||||
247
SupplierManager/Controllers/LoginController.cs
Normal file
247
SupplierManager/Controllers/LoginController.cs
Normal file
@@ -0,0 +1,247 @@
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Text;
|
||||
using ViewModels;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ViewModels.RequestData;
|
||||
using ViewModels.ResponseData;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
using NLog;
|
||||
using SupplierManager.Extensions;
|
||||
using SupplierManager.Models;
|
||||
using ViewModels.Common;
|
||||
using static IronPython.Modules._ast;
|
||||
|
||||
namespace WebAPIServer.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class LoginController : ControllerBase
|
||||
{
|
||||
|
||||
|
||||
|
||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
public IConfiguration? configuration { get; set; }
|
||||
public LoginController(IConfiguration _configuration)
|
||||
{
|
||||
configuration = _configuration;
|
||||
}
|
||||
[Authorize()]
|
||||
[HttpPost()]
|
||||
public ReturnInfo TokenXuQi()
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
r.isok = false;
|
||||
try
|
||||
{
|
||||
var claims = HttpContext.AuthenticateAsync().Result?.Principal?.Claims;
|
||||
if (claims != null && claims.Any())
|
||||
{
|
||||
var Name = claims.SingleOrDefault(A => A.Type == ClaimTypes.Name)?.Value;
|
||||
var UUU = claims.SingleOrDefault(A => A.Type == ClaimTypes.Role)?.Value;
|
||||
var TTT = claims.SingleOrDefault(A => A.Type == ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
AasUser? HH = new AasUser();
|
||||
int a = 0;
|
||||
int.TryParse(TTT, out a);
|
||||
HH.Id = a;
|
||||
bool bl = false;
|
||||
bool.TryParse(UUU, out bl);
|
||||
HH.Username = Name;
|
||||
string TokenStr = GetToken(HH);
|
||||
r.isok = true;
|
||||
r.response = TokenStr;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
/// <param name="username">用户名</param>
|
||||
/// <param name="password">密码</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ReturnInfo Login([FromBody] LoginData data)
|
||||
{
|
||||
|
||||
ReturnInfo res = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
string password = data.password;
|
||||
string username = data.username;
|
||||
AasUser? entity = null;
|
||||
string TokenString = "";
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
entity = q.AasUsers.SingleOrDefault(A => A.Username.Equals(username)&&A.Isdelete==false);
|
||||
if (entity != null)
|
||||
{
|
||||
bool vvv = Tools.VerifyHashedPassword(entity.Password, password);
|
||||
if (vvv == false)
|
||||
{
|
||||
res.isok = false;
|
||||
res.message = "密码错误";
|
||||
}
|
||||
else
|
||||
{
|
||||
TokenString = GetToken(entity);
|
||||
res.isok = true;
|
||||
|
||||
|
||||
ResLoginData r = new ResLoginData();
|
||||
r.AccessToken = TokenString;
|
||||
r.Id = entity.Id;
|
||||
r.Username = entity.Username;
|
||||
r.Realname = entity.Realname;
|
||||
r.Position = entity.Position;
|
||||
r.ComId = entity.ComId;
|
||||
r.RoleId = entity.RoleId;
|
||||
r.Avatar = entity.Avatar;
|
||||
|
||||
res.response = r;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.isok = false;
|
||||
res.message = "用户不存在";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
res.message = ex.Message;
|
||||
res.isok = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
/// wy登录验证
|
||||
/// </summary>
|
||||
/// <param name="username">用户名</param>
|
||||
/// <param name="password">密码</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ReturnInfo WeLogin([FromBody] LoginData data)
|
||||
{
|
||||
|
||||
ReturnInfo res = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
string password = data.password;
|
||||
string username = data.username;
|
||||
AasUser? entity = null;
|
||||
string TokenString = "";
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
entity = q.AasUsers.SingleOrDefault(A => A.Username.Equals(username)&&A.Isdelete==false);
|
||||
if (entity != null)
|
||||
{
|
||||
bool vvv = Tools.VerifyHashedPassword(entity.Password, password);
|
||||
if (vvv == false)
|
||||
{
|
||||
res.isok = false;
|
||||
res.message = "密码错误";
|
||||
}
|
||||
else
|
||||
{
|
||||
TokenString = GetToken(entity);
|
||||
res.isok = true;
|
||||
|
||||
JWTData r = new()
|
||||
{
|
||||
AccessToken = TokenString,
|
||||
iss = "BLW-" + Guid.NewGuid().ToString(),
|
||||
exp = Tools.ToUnixTimestampBySeconds(DateTime.Now.AddHours(12)),
|
||||
iat = Tools.ToUnixTimestampBySeconds(DateTime.Now).ToString(),
|
||||
jti = "AAS-" + Guid.NewGuid().ToString(),
|
||||
};
|
||||
|
||||
res.response = r;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.isok = false;
|
||||
res.message = "用户不存在";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
res.message = ex.Message;
|
||||
res.isok = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private string GetToken(AasUser? entity)
|
||||
{
|
||||
string TokenString;
|
||||
var claims = new Claim[]
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, entity.Id.ToString()),
|
||||
new Claim(ClaimTypes.MobilePhone, entity.Mobile.ToString()),
|
||||
new Claim(ClaimTypes.Name, entity.Username)
|
||||
};
|
||||
|
||||
var secretByte = Encoding.UTF8.GetBytes(configuration["JwT:SecretKey"]);
|
||||
var signingKey = new SymmetricSecurityKey(secretByte);
|
||||
var a = SecurityAlgorithms.HmacSha256;
|
||||
|
||||
var signingCredentials = new SigningCredentials(signingKey, a);
|
||||
|
||||
var token = new JwtSecurityToken(
|
||||
issuer: configuration["JwT:Issuer"],
|
||||
audience: configuration["JwT:Audience"],//接收
|
||||
claims: claims,//存放的用户信息
|
||||
notBefore: DateTime.UtcNow,//发布时间
|
||||
expires: DateTime.UtcNow.AddHours(12),
|
||||
signingCredentials: signingCredentials
|
||||
//有效期设置为1天signingCredentials //数字名
|
||||
);
|
||||
TokenString = new JwtSecurityTokenHandler().WriteToken(token);
|
||||
return TokenString;
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public string Helloooo()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
internal class TblUtsManageUser
|
||||
{
|
||||
public object Id { get; internal set; }
|
||||
public bool IsAdmin { get; internal set; }
|
||||
public string? UserName { get; internal set; }
|
||||
}
|
||||
}
|
||||
20
SupplierManager/Controllers/PanelSelectionController.cs
Normal file
20
SupplierManager/Controllers/PanelSelectionController.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ViewModels;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class PanelSelectionController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
381
SupplierManager/Controllers/UsersController.cs
Normal file
381
SupplierManager/Controllers/UsersController.cs
Normal file
@@ -0,0 +1,381 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SupplierManager.Models;
|
||||
using ViewModels;
|
||||
using ViewModels.Common;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class UsersController : ControllerBase
|
||||
{
|
||||
public class duser
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="LLL"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo DelUser([FromBody] duser LLL)
|
||||
{
|
||||
ReturnInfo returnInfo = new();
|
||||
if(LLL.Id == 2 || LLL.Id == 1)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = "超级管理员不可删除!";
|
||||
return returnInfo;
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
var FFF = q.AasUsers.FirstOrDefault(A => A.Id == LLL.Id);
|
||||
if (FFF != null)
|
||||
{
|
||||
FFF.Isdelete = true;
|
||||
q.AasUsers.Update(FFF);
|
||||
q.SaveChanges();
|
||||
returnInfo.isok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
/// </summary>
|
||||
/// <param name="LLL"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo EditUser([FromBody] ReturnUser LLL)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
var lll = q.AasUsers.SingleOrDefault(A => A.Id == LLL.Id);
|
||||
if (lll != null)
|
||||
{
|
||||
|
||||
string username = LLL.Username;
|
||||
int? companyId = LLL.ComId;
|
||||
string mobile = LLL.Mobile;
|
||||
string weiXin = LLL.Weixin;
|
||||
string email = LLL.Email;
|
||||
|
||||
lll.Realname = LLL.Realname;
|
||||
lll.RoleId = LLL.RoleId;
|
||||
lll.Position = LLL.Position;
|
||||
if (!string.IsNullOrWhiteSpace(LLL.Avatar))
|
||||
{
|
||||
lll.Avatar = "Uploads/face/" + LLL.Avatar;
|
||||
}
|
||||
lll.Username = username;
|
||||
lll.ComId = companyId;
|
||||
lll.Mobile = mobile;
|
||||
lll.Weixin = weiXin;
|
||||
lll.Email = email;
|
||||
lll.UpdateTime = DateTime.Now;
|
||||
|
||||
string PPP = LLL.Password.Trim();
|
||||
if (!string.IsNullOrWhiteSpace(PPP))
|
||||
{
|
||||
lll.Password = Tools.HashPassword(PPP);
|
||||
lll.PswEncryption = Tools.EncryptString(PPP);
|
||||
}
|
||||
|
||||
q.AasUsers.Update(lll);
|
||||
q.SaveChanges();
|
||||
returnInfo.isok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码
|
||||
/// </summary>
|
||||
/// <param name="LLL"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo ModifyPassWord([FromBody] PWD_Reset LLL)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
var QQQ = q.AasUsers.SingleOrDefault(A => A.Id == LLL.Id);
|
||||
if (QQQ != null)
|
||||
{
|
||||
QQQ.Password = Tools.HashPassword(LLL.PlaintextPwd);
|
||||
QQQ.PswEncryption = Tools.EncryptString(LLL.PlaintextPwd);
|
||||
q.AasUsers.Update(QQQ);
|
||||
q.SaveChanges();
|
||||
returnInfo.isok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
/// <summary>
|
||||
/// 新增密码为123456
|
||||
/// </summary>
|
||||
/// <param name="LLL"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo ResetPassWord([FromBody] PWD_Reset LLL)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
var Q = q.AasUsers.SingleOrDefault(A => A.Id == LLL.Id);
|
||||
if (Q != null)
|
||||
{
|
||||
Q.Password = Tools.HashPassword("123456");
|
||||
Q.PswEncryption = Tools.EncryptString("123456");
|
||||
q.AasUsers.Update(Q);
|
||||
q.SaveChanges();
|
||||
returnInfo.isok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户信息
|
||||
/// </summary>
|
||||
/// <param name="S"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public ReturnInfo GetUserInfo([FromBody] QueryAll_Or_Single S)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
if (S.IsAll)
|
||||
{
|
||||
returnInfo.isok = true;
|
||||
returnInfo.response = q.AasUsers.Where(A=>!A.Isdelete).Select(F => new ReturnUser
|
||||
{
|
||||
Id = F.Id,
|
||||
Username = F.Username,
|
||||
Realname = F.Realname,
|
||||
RoleId = F.RoleId,
|
||||
Email = F.Email,
|
||||
Weixin = F.Weixin,
|
||||
Position = F.Position,
|
||||
Avatar = F.Avatar,
|
||||
ComId = F.ComId,
|
||||
Mobile = F.Mobile,
|
||||
}).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
returnInfo.isok = true;
|
||||
var a = q.AasUsers.SingleOrDefault(A => A.Id == S.ID);
|
||||
if (a != null)
|
||||
{
|
||||
ReturnUser u = new ReturnUser();
|
||||
u.Id = a.Id;
|
||||
u.Username = a.Username;
|
||||
u.Realname = a.Realname;
|
||||
u.RoleId = a.RoleId;
|
||||
u.ComId = a.ComId;
|
||||
u.Mobile = a.Mobile;
|
||||
u.Weixin = a.Weixin;
|
||||
u.Position = a.Position;
|
||||
u.Avatar = a.Avatar;
|
||||
u.Email = a.Email;
|
||||
returnInfo.response = u;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户
|
||||
/// </summary>
|
||||
/// <param name="LLL"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
//[Authorize()]
|
||||
public ReturnInfo AddUser([FromBody] ReturnUser LLL)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
string username = LLL.Username;
|
||||
int? companyId = LLL.ComId;
|
||||
string mobile = LLL.Mobile;
|
||||
string weiXin = LLL.Weixin;
|
||||
string email = LLL.Email;
|
||||
|
||||
AasUser lll = new AasUser();
|
||||
lll.Username = username;
|
||||
lll.Realname = LLL.Realname;
|
||||
lll.ComId = LLL.ComId;
|
||||
lll.RoleId = LLL.RoleId;
|
||||
lll.Position = LLL.Position;
|
||||
lll.Weixin = LLL.Weixin;
|
||||
lll.Email = email;
|
||||
lll.Mobile = mobile;
|
||||
if (!string.IsNullOrWhiteSpace(LLL.Avatar))
|
||||
{
|
||||
lll.Avatar = "Uploads/face/" + LLL.Avatar;
|
||||
}
|
||||
lll.Isdelete = false;
|
||||
|
||||
lll.CreationTime = DateTime.Now;
|
||||
lll.UpdateTime = DateTime.Now;
|
||||
|
||||
using (var q = new AgentApprovalSystemContext())
|
||||
{
|
||||
var Q = q.AasUsers.Where(A => A.Username.Equals(username));
|
||||
if (Q.Count() > 0)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = "此用户名已经存在";
|
||||
}
|
||||
else
|
||||
{
|
||||
//lll.Password = Tools.HashPassword("123456");
|
||||
//lll.PswEncryption = Tools.EncryptString("123456");
|
||||
|
||||
lll.Password = Tools.HashPassword(LLL.Password.Trim());
|
||||
lll.PswEncryption = Tools.EncryptString(LLL.Password.Trim());
|
||||
q.AasUsers.Add(lll);
|
||||
returnInfo.isok = true;
|
||||
}
|
||||
q.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回用户信息
|
||||
/// </summary>
|
||||
public class ReturnUser
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public int Id { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 用户名(登录名)
|
||||
/// </summary>
|
||||
public string? Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 真实姓名
|
||||
/// </summary>
|
||||
public string? Realname { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属公司ID
|
||||
/// </summary>
|
||||
public int? ComId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 角色ID
|
||||
/// </summary>
|
||||
public int? RoleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 职位
|
||||
/// </summary>
|
||||
public string? Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string Password { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 密码加密处理
|
||||
/// </summary>
|
||||
public string PswEncryption { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 微信号
|
||||
/// </summary>
|
||||
public string? Weixin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 邮箱
|
||||
/// </summary>
|
||||
public string? Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 电话号码
|
||||
/// </summary>
|
||||
public string? Mobile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 账户头像
|
||||
/// </summary>
|
||||
public string? Avatar { get; set; }
|
||||
}
|
||||
public class PWD_Reset
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string PlaintextPwd { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
41
SupplierManager/Controllers/WeatherForecastController.cs
Normal file
41
SupplierManager/Controllers/WeatherForecastController.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SupplierManager.Models;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public string AAA()
|
||||
{
|
||||
//using var q = new AgentApprovalSystemContext();
|
||||
//q.AasCompanyInfos.ToLinqToDB().LeftJoin(A=>A.Id==A.Id);
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
}
|
||||
143
SupplierManager/Controllers/WyUsersController.cs
Normal file
143
SupplierManager/Controllers/WyUsersController.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SupplierManager.Models;
|
||||
using ViewModels;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class WyUsersController : ControllerBase
|
||||
{
|
||||
private readonly AgentApprovalSystemContext _context;
|
||||
|
||||
public WyUsersController(AgentApprovalSystemContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/WyUsers
|
||||
[HttpPost()]
|
||||
public async Task<ReturnInfo> GetUserInfo([FromBody] QueryAll_Or_Single S)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
r.isok = true;
|
||||
r.response= await _context.WyUsers.ToListAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message=ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
[Authorize()]
|
||||
public async Task<ReturnInfo> EditWyUser(WyUser wyUser)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
if (!WyUserExists(wyUser.Id))
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = "此用户不存在";
|
||||
}
|
||||
else
|
||||
{
|
||||
_context.Entry(wyUser).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
|
||||
string Introduced = JsonSerializer.Serialize(wyUser);
|
||||
string ReturnValue = JsonSerializer.Serialize(r);
|
||||
await LogRecord(Introduced, ReturnValue);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
private string GetIP()
|
||||
{
|
||||
string? ip = string.Empty;
|
||||
string? NNN = HttpContext?.Request?.HttpContext?.Connection?.RemoteIpAddress?.ToString();
|
||||
if (string.IsNullOrEmpty(NNN))
|
||||
{
|
||||
ip = HttpContext?.Request.Headers["HTTP_X_FORWARDED_FOR"];
|
||||
}
|
||||
else
|
||||
{
|
||||
ip = NNN;
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize()]
|
||||
public async Task<ReturnInfo> AddWyUser(List<WyUser> wyUser)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
_context.WyUsers.AddRange(wyUser);
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
|
||||
string Introduced = JsonSerializer.Serialize(wyUser);
|
||||
string ReturnValue = JsonSerializer.Serialize(r);
|
||||
await LogRecord(Introduced, ReturnValue);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
private async Task LogRecord(string Introduced, string ReturnValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
WyLog wx = new WyLog();
|
||||
wx.Ip = GetIP();
|
||||
wx.Operation = "Edit";
|
||||
wx.Introduced = Introduced;
|
||||
wx.ReturnValue = ReturnValue;
|
||||
wx.CreationTime = Tools.ToUnixTimestampBySeconds(DateTime.Now);
|
||||
_context.WyLogs.Add(wx);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private bool WyUserExists(long id)
|
||||
{
|
||||
return _context.WyUsers.Any(e => e.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user