Initial_commit_SecMPS_v2
This commit is contained in:
@@ -0,0 +1,240 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using VolPro.Core.Controllers.Basic;
|
||||
using VolPro.Core.DBManager;
|
||||
using VolPro.Core.DbSqlSugar;
|
||||
using VolPro.Core.Enums;
|
||||
using VolPro.Core.Extensions;
|
||||
using VolPro.Core.Filters;
|
||||
using VolPro.Core.ManageUser;
|
||||
using VolPro.Core.Utilities;
|
||||
using VolPro.Entity.AttributeManager;
|
||||
using VolPro.Entity.DomainModels;
|
||||
|
||||
namespace VolPro.WebApi.Controllers.DataView
|
||||
{
|
||||
[Route("api/dataview/project")]
|
||||
[PermissionTable(Name = nameof(DataViewProjects))]
|
||||
public class DataViewProjectController : VolController
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
public DataViewProjectController(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
[Route("list"), HttpGet]
|
||||
public async Task<IActionResult> GetList(int page = 1, int limit = 12)
|
||||
{
|
||||
var query = DBServerProvider.DbContext.Set<DataViewProjects>().Where(x => x.IsDel == 0);
|
||||
var data = await query.OrderByDescending(x => x.OrderNo)
|
||||
.ThenByDescending(x => x.CreateDate)
|
||||
.TakePage(page, limit)
|
||||
.ToListAsync();
|
||||
return Json(new
|
||||
{
|
||||
code = 200,
|
||||
msg = "获取成功",
|
||||
count = await query.CountAsync(),
|
||||
data = data
|
||||
});
|
||||
}
|
||||
|
||||
[Route("create"), HttpPost]
|
||||
[ApiActionPermission(ActionPermissionOptions.Add | ActionPermissionOptions.Update)]
|
||||
public IActionResult Create([FromBody] DataViewProjects data)
|
||||
{
|
||||
var id = new IdWorker();
|
||||
data.Id = id.NextId();
|
||||
|
||||
return Success("获取成功", data);
|
||||
}
|
||||
|
||||
|
||||
[Route("getData"), HttpGet]
|
||||
public async Task<IActionResult> GetData(long projectId)
|
||||
{
|
||||
var data = await DBServerProvider.DbContext.Set<DataViewProjects>().Where(x => x.Id == projectId).FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
{
|
||||
return Success();
|
||||
}
|
||||
return Success("获取成功", data);
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
[Route("save/data"), HttpPost]
|
||||
[ApiActionPermission(ActionPermissionOptions.Add | ActionPermissionOptions.Update)]
|
||||
public IActionResult SaveData(IFormCollection formdata)
|
||||
{
|
||||
DataViewProjects data = new DataViewProjects();
|
||||
data.Id = Convert.ToInt64(formdata["projectId"]);
|
||||
data.Content = formdata["Content"];
|
||||
return UpdateData(data, x => new { x.Content });
|
||||
}
|
||||
/// <summary>
|
||||
/// 编辑项目名称
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
[Route("edit"), HttpPost]
|
||||
[ApiActionPermission(ActionPermissionOptions.Add | ActionPermissionOptions.Update)]
|
||||
public IActionResult Edit([FromBody] DataViewProjects data)
|
||||
{
|
||||
data = HttpContext.GetRequestParameters().DeserializeObject<DataViewProjects>();
|
||||
return UpdateData(data, x => new { x.ProjectName });
|
||||
}
|
||||
|
||||
[Route("publish"), HttpPost, HttpPut]
|
||||
[ApiActionPermission(ActionPermissionOptions.Add | ActionPermissionOptions.Update)]
|
||||
public IActionResult Publish([FromBody] DataViewProjects data)
|
||||
{
|
||||
data = HttpContext.GetRequestParameters().DeserializeObject<DataViewProjects>();
|
||||
return UpdateData(data, x => new { x.State });
|
||||
}
|
||||
|
||||
private static object dataviewLockObject = new object();
|
||||
private IActionResult UpdateData(DataViewProjects data, Expression<Func<DataViewProjects, object>> updateField)
|
||||
{
|
||||
lock (dataviewLockObject)
|
||||
{
|
||||
var dbContext = DBServerProvider.DbContext.Set<DataViewProjects>();
|
||||
var dataView = dbContext.Where(x => x.Id == data.Id).FirstOrDefault();
|
||||
if (dataView != null)
|
||||
{
|
||||
var arr = updateField.GetExpressionToArray();
|
||||
//foreach (var field in arr)
|
||||
//{
|
||||
// DBServerProvider.DbContext.Entry<DataViewProjects>(data).Property(field).IsModified = true;
|
||||
//}
|
||||
DBServerProvider.DbContext.Update(data, arr);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.IsDel = 0;
|
||||
data.SetCreateDefaultVal();
|
||||
data.DbServiceId = UserContext.CurrentServiceId;
|
||||
DBServerProvider.DbContext.Add(data);
|
||||
}
|
||||
DBServerProvider.DbContext.SaveChanges();
|
||||
}
|
||||
return Success();
|
||||
}
|
||||
|
||||
|
||||
[Route("upload"), HttpPost]
|
||||
|
||||
public IActionResult Upload(List<IFormFile> fileInput)
|
||||
{
|
||||
string fullPath = "dataView".MapPath(true);
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(fullPath)) Directory.CreateDirectory(fullPath);
|
||||
for (int i = 0; i < fileInput.Count; i++)
|
||||
{
|
||||
string fileName = fileInput[i].FileName;
|
||||
string id = fileInput[i].FileName.Split("_")[0];
|
||||
using (var stream = new FileStream(fullPath + "\\" + fileName, FileMode.Create))
|
||||
{
|
||||
fileInput[i].CopyTo(stream);
|
||||
}
|
||||
DataViewProjects data = new DataViewProjects()
|
||||
{
|
||||
Id = Convert.ToInt64(id),
|
||||
IndexImage = "dataView\\" + fileName
|
||||
};
|
||||
UpdateData(data, x => new { x.IndexImage });
|
||||
}
|
||||
return Json(new
|
||||
{
|
||||
code = 200,
|
||||
msg = "ok",
|
||||
data = new { fileurl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/dataView/{ fileInput[0].FileName}" }
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Success(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 编辑项目名称
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
[Route("delete"), HttpDelete,HttpGet,HttpPost]
|
||||
[ApiActionPermission(ActionPermissionOptions.Add | ActionPermissionOptions.Update | ActionPermissionOptions.Delete)]
|
||||
public IActionResult Delete(long ids)
|
||||
{
|
||||
DataViewProjects dataView = new DataViewProjects() { Id = ids, IsDel = 1 };
|
||||
DBServerProvider.DbContext.Update(dataView,x=>new { x.IsDel });
|
||||
DBServerProvider.DbContext.SaveChanges();
|
||||
return Success("删除成功");
|
||||
}
|
||||
|
||||
[Route("updateOrderNo"), HttpPost]
|
||||
[ApiActionPermission(ActionPermissionOptions.Add | ActionPermissionOptions.Update)]
|
||||
public IActionResult UpdateOrderNo([FromBody] DataViewProjects data)
|
||||
{
|
||||
data = HttpContext.GetRequestParameters().DeserializeObject<DataViewProjects>();
|
||||
UpdateData(data, x => new { x.OrderNo, x.ProjectName });
|
||||
return Success("修改成功");
|
||||
}
|
||||
|
||||
|
||||
[Route("copy"), HttpPost]
|
||||
[ApiActionPermission(ActionPermissionOptions.Add | ActionPermissionOptions.Update)]
|
||||
public async Task<IActionResult> Copy([FromBody] DataViewProjects data)
|
||||
{
|
||||
data = HttpContext.GetRequestParameters().DeserializeObject<DataViewProjects>();
|
||||
long dataId= data.Id;
|
||||
data = await DBServerProvider.DbContext.Set<DataViewProjects>().Where(x => x.Id == data.Id).FirstOrDefaultAsync();
|
||||
if (data==null)
|
||||
{
|
||||
string msg = $"未查到id数据:{dataId}";
|
||||
Console.WriteLine(msg);
|
||||
return Success(msg);
|
||||
}
|
||||
var id = new IdWorker();
|
||||
data.Id = id.NextId();
|
||||
data.ProjectName = data.ProjectName + "副本";
|
||||
data.SetCreateDefaultVal();
|
||||
DBServerProvider.DbContext.Add(data);
|
||||
DBServerProvider.DbContext.SaveChanges();
|
||||
return Success("修改成功");
|
||||
}
|
||||
|
||||
private new IActionResult Success(string msg = "ok")
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
code = 200,
|
||||
msg = msg
|
||||
});
|
||||
}
|
||||
|
||||
private new IActionResult Success(string msg, object data)
|
||||
{
|
||||
|
||||
return Json(new
|
||||
{
|
||||
code = 200,
|
||||
msg = msg,
|
||||
data = data
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using VolPro.Core;
|
||||
using VolPro.Core.Configuration;
|
||||
using VolPro.Core.Controllers.Basic;
|
||||
using VolPro.Core.DbSqlSugar;
|
||||
using VolPro.Core.Enums;
|
||||
using VolPro.Core.Extensions;
|
||||
using VolPro.Core.ManageUser;
|
||||
using VolPro.Core.ObjectActionValidator;
|
||||
using VolPro.Core.Services;
|
||||
using VolPro.Core.Utilities;
|
||||
using VolPro.Entity.DomainModels;
|
||||
using VolPro.Sys.IRepositories;
|
||||
using VolPro.Sys.IServices;
|
||||
|
||||
namespace VolPro.WebApi.Controllers.DataView
|
||||
{
|
||||
[Route("api/dataview/sys")]
|
||||
|
||||
public class DataViewSysController : VolController
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ISys_UserRepository _userRepository;
|
||||
private readonly ISys_MenuService _menuService;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
public DataViewSysController(IHttpContextAccessor httpContextAccessor,
|
||||
ISys_UserRepository userRepository,
|
||||
ISys_MenuService menuService,
|
||||
IMemoryCache memoryCache)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userRepository = userRepository;
|
||||
_memoryCache = memoryCache;
|
||||
_menuService = menuService;
|
||||
}
|
||||
[Route("login"), HttpPost, AllowAnonymous]
|
||||
[ObjectModelValidatorFilter(ValidatorModel.Login)]
|
||||
public async Task<IActionResult> Login([FromBody] LoginInfo loginInfo)
|
||||
{
|
||||
|
||||
WebResponseContent webResponse = new WebResponseContent();
|
||||
string msg = string.Empty;
|
||||
|
||||
string cacheCode = (_memoryCache.Get(loginInfo.UUID) ?? "").ToString();
|
||||
if (string.IsNullOrEmpty(cacheCode))
|
||||
{
|
||||
return Error("验证码已失效".Translator());
|
||||
}
|
||||
if (cacheCode.ToLower() != loginInfo.VerificationCode.ToLower())
|
||||
{
|
||||
_memoryCache.Remove(loginInfo.UUID);
|
||||
return Error("验证码不正确".Translator());
|
||||
}
|
||||
try
|
||||
{
|
||||
var user = await _userRepository.FindAsIQueryable(x => x.UserName == loginInfo.UserName)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (user == null || loginInfo.Password.Trim().EncryptDES(AppSetting.Secret.User) != (user.UserPwd ?? ""))
|
||||
return Error("账号或密码不正确");
|
||||
|
||||
string token = JwtHelper.IssueJwt(new UserInfo()
|
||||
{
|
||||
User_Id = user.User_Id,
|
||||
UserName = user.UserName,
|
||||
Role_Id = user.Role_Id ?? 0
|
||||
}, 43200);
|
||||
user.Token = token;
|
||||
webResponse.Data = new { token, userName = user.UserTrueName, img = user.HeadImageUrl };
|
||||
_userRepository.Update(user, x => x.Token, true);
|
||||
UserContext.Current.LogOut(user.User_Id);
|
||||
|
||||
loginInfo.Password = string.Empty;
|
||||
|
||||
var menu = _menuService.GetUserMenuList(UserContext.Current.GetUserInfo(user.User_Id).RoleIds)
|
||||
.Where(x => x.LinkType == 4 && (x.Enable == null || x.Enable == 1))
|
||||
.Select(s => new { s.MenuName, s.Url }).ToList();
|
||||
|
||||
|
||||
// return webResponse.OK(ResponseType.LoginSuccess);
|
||||
return Json(new
|
||||
{
|
||||
msg = "操作成功",
|
||||
code = 200,
|
||||
data = new
|
||||
{
|
||||
userinfo = new
|
||||
{
|
||||
id = "0",
|
||||
username = user.UserTrueName,// "admin",
|
||||
// password = "21232f297a57a5a743894a0e4a801fc3",
|
||||
nickname = user.UserTrueName
|
||||
},
|
||||
token = new
|
||||
{
|
||||
tokenName = "Authorization",
|
||||
tokenValue = $"Bearer {token}",
|
||||
isLogin = true,
|
||||
loginId = "1",
|
||||
loginType = "login",
|
||||
tokenTimeout = 2592000 * 600,
|
||||
sessionTimeout = 2592000 * 600,
|
||||
tokenSessionTimeout = 2591893,
|
||||
tokenActivityTimeout = -1,
|
||||
loginDevice = "default-device"
|
||||
},
|
||||
menu = menu
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message + ex.StackTrace;
|
||||
if (HttpContext.GetService<Microsoft.AspNetCore.Hosting.IWebHostEnvironment>().IsDevelopment())
|
||||
{
|
||||
throw new Exception(ex.Message + ex.StackTrace);
|
||||
}
|
||||
return Error(msg);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_memoryCache.Remove(loginInfo.UUID);
|
||||
Logger.Info(LoggerType.Login, loginInfo.Serialize(), webResponse.Message, msg);
|
||||
}
|
||||
|
||||
|
||||
//return Json(data);
|
||||
}
|
||||
/// <summary>
|
||||
/// 2020.06.15增加登陆验证码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet, Route("getVierificationCode"), AllowAnonymous]
|
||||
public IActionResult GetVierificationCode()
|
||||
{
|
||||
string code = VierificationCode.RandomText();
|
||||
var data = new
|
||||
{
|
||||
img = VierificationCode.CreateBase64Imgage(code),
|
||||
uuid = Guid.NewGuid()
|
||||
};
|
||||
_memoryCache.Set(data.uuid.ToString(), code, new TimeSpan(0, 5, 0));
|
||||
return Json(new { code = 200, data = data });
|
||||
}
|
||||
[Route("logout"), HttpGet, AllowAnonymous]
|
||||
public IActionResult LogOut()
|
||||
{
|
||||
return Json(new { code = 200, msg = "ok" });
|
||||
}
|
||||
[HttpGet, Route("getOssInfo"), AllowAnonymous]
|
||||
public IActionResult GetOssInfo()
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
bucketName = "dataview",
|
||||
bucketURL = ""
|
||||
});
|
||||
}
|
||||
|
||||
private new IActionResult Error(string msg = "error")
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
code = 0,
|
||||
msg = msg
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using VolPro.Core.Controllers.Basic;
|
||||
using VolPro.Core.Utilities;
|
||||
using VolPro.Entity.AttributeManager;
|
||||
using VolPro.Entity.DomainModels;
|
||||
using VolPro.Sys.IRepositories;
|
||||
|
||||
namespace VolPro.WebApi.Controllers.DataView
|
||||
{
|
||||
/// <summary>
|
||||
/// 所有接口路由都要以api/dataview开头
|
||||
/// </summary>
|
||||
[Route("api/dataview/test")]
|
||||
|
||||
public class DataViewTestController : VolController
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ISys_UserRepository _userRepository;
|
||||
public DataViewTestController(IHttpContextAccessor httpContextAccessor, ISys_UserRepository userRepository)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
[Route("Text1"), HttpGet,HttpPost]
|
||||
public async Task<IActionResult> Text1()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
return Json(new { value=DateTime.Now});
|
||||
}
|
||||
[Route("data1"), HttpGet]
|
||||
public async Task<IActionResult> Data1()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
return Json(new { });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user