using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Model.ModelDto.SysDto;
using Model.ModelVm;
using WMS.Entity;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
using SqlSugar;
using Model.ModelVm.SysVm;
using Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments;
using Utility.Tools;
using WMS.IBLL.ILogServer;
using WMS.Entity.LogEntity;
using System.Security.Cryptography;
using System.Data;
using Model.ModelDto.LogDto;
using Utility;
using Model.ModelVm.LogVm;
namespace Wms.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize]
public class BasisController : ControllerBase
{
///
/// 依赖注入
///
private readonly ICustomerServer _customerSvc;//客户Svc
private readonly ILogisticsInfoServer _logisticsSvc;//物流Svc
private readonly IUnitServer _unitSvc;//单位Svc
private readonly IPackagServer _packagSvc; // 包装
private readonly IMaterialsServer _mate; // 包装
private readonly IUserInforServer _userInforServer; //用户
private readonly IRolesServer _rolesServer; //角色
private readonly IRoleRightServer _roleRightServer; //角色权限
private readonly IRBACServer _rBACServer; //RBAC
private readonly IDepartmentServer _department; //部门
private readonly IFunSettingServer _setting; //功能设定
private readonly IInterfaceServer _interface;//接口管理
private readonly IOperationSysServer _operation; //操作日志
private readonly UserManager _userManager;
///
/// 构造函数
///
/// 客户
/// 物流
/// 用户
/// 角色
/// 角色权限
/// RBAC
/// 单位
/// 物料
/// 部门
/// 功能设定
/// 操作日志
public BasisController(ICustomerServer customerSvc, ILogisticsInfoServer logisticsSvc, IUserInforServer userInforServer, IRolesServer rolesServer, IRoleRightServer roleRightServer, IRBACServer rBACServer, IUnitServer unitSvc, IPackagServer packagServer, IMaterialsServer mate, IDepartmentServer department, IFunSettingServer setting, IInterfaceServer interfaceS, IOperationSysServer operation, UserManager userManager)
{
_customerSvc = customerSvc;//客户Svc
_logisticsSvc = logisticsSvc;//物流Svc
_userInforServer = userInforServer;//用户
_rolesServer = rolesServer;//角色
_roleRightServer = roleRightServer;//角色权限
_rBACServer = rBACServer;//RBAC
_unitSvc = unitSvc;//单位
_packagSvc = packagServer; // 包装
_mate = mate; //物料
_department = department;//部门
_setting = setting; //功能设定
_interface = interfaceS;//接口管理
_operation = operation; //操作日志
_userManager = userManager;
}
//基本信息管理
#region 用户管理
#region 用户管理
///
/// 获取用户角色信息
///
/// 登录名称
/// 部门号
/// 角色号
/// 状态
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetUserRoleList(string UserName, string DepartmentNo, string RoleNo, string Status)
{
return await _userInforServer.GetUserRoleList(UserName, DepartmentNo, RoleNo, Status);
}
///
/// 根据id获取用户信息列表
///
/// 用户id
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task GetUserinfoListById(int id)
{
return await _userInforServer.GetUserInfoById(id);
}
///
/// 新增用户信息
///
/// 用户dto模型
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task InsertUserinfo(UserInfoDto UserInfoDto)
{
await _userInforServer.InsertUserInfo(UserInfoDto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "用户管理",
FkNo = UserInfoDto.UserNo,
TypeName = "添加",
Msg = "添加用户信息 用户号:" + UserInfoDto.UserNo
});
}
///
/// 删除\批删用户信息
///
/// 用户id
///
/// 异常
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task DeleteUserInfo(int userids)
{
//获取用户信息
SysUserInfor user = await _userInforServer.GetUserInfoById(userids);
await _userInforServer.DeleteUserinfo(user);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "用户管理",
FkNo = user.UserNo,
TypeName = "删除",
Msg = "删除用户信息 用户号:" + user.UserNo
});
}
///
/// 编辑用户信息
///
/// 用户dto模型
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task UpdateUserinfo(UserInfoDto userdto)
{
await _userInforServer.UpdateUserinfo(userdto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "用户管理",
FkNo = userdto.UserNo,
TypeName = "编辑",
Msg = "修改用户信息 用户号:" + userdto.UserNo
});
}
#endregion
#region 修改密码
///// 用户id
///
/// 修改用户密码
///
/// 原密码
/// 新密码
/// 确认密码
///
/// 捕获异常
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task UptUserPassWord(string pwdOld, string pwdNew, string pwdNewTwo/*, int userId*/)
{
pwdOld = Md5Tools.CalcMd5(pwdOld);
pwdNew = Md5Tools.CalcMd5(pwdNew);
pwdNewTwo = Md5Tools.CalcMd5(pwdNewTwo);
//获取当前操作用户id
SysUserInfor user = await _userInforServer.GetUserInfoById(_userManager.UserId);
if (user == null)
throw Oops.Bah("找不到用户信息");
if (user.PassWord != pwdOld)
throw Oops.Bah("原密码不正确");
//修改密码
int i = await _userInforServer.UptUserPassWord(pwdNew, _userManager.UserId);
if (i <= 0)
throw Oops.Bah("修改密码失败");
}
///
/// x天后提醒用户修改密码
///
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task IsPassWordTime()
{
return await _userInforServer.IsPassWordTime(_userManager.UserId);
}
#endregion
#endregion
#region 角色管理
///
/// 查询角色信息列表
///
/// 角色号
/// 角色名称
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetRolesList(string RoleNo, string RoleName)
{
return await _rolesServer.GetRoleList(RoleNo, RoleName);
}
///
/// 根据id获取角色信息列表
///
/// 角色id
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task GetRolesListById(int roleid)
{
return await _rolesServer.GetRoleInfoById(roleid);
}
///
/// 新增角色信息
///
/// 角色dto
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task InsertRoleInfo(RoleDto roledto)
{
await _rolesServer.InsertRoleInfo(roledto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "角色权限",
FkNo = roledto.RoleNo,
TypeName = "添加",
Msg = "添加角色信息 角色号:" + roledto.RoleNo
});
}
///
/// 删除角色信息
///
/// 角色id
///
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task DeleteRoleInfo(int roleids)
{
//根据角色id获取角色信息
SysRoles role = await _rolesServer.GetRoleInfoById(roleids);
await _rolesServer.DeleteRoleInfo(role);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "角色权限",
FkNo = role.RoleNo,
TypeName = "删除",
Msg = "删除角色信息 角色号:" + role.RoleNo
});
}
///
/// 编辑角色信息
///
/// 角色实体模型
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task UpdateRolesInfo(SysRoles role)
{
await _rolesServer.UpdateRoleInfo(role);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "角色权限",
FkNo = role.RoleNo,
TypeName = "编辑",
Msg = "修改角色信息 角色号:" + role.RoleNo
});
}
#endregion
#region 角色权限管理
///
/// 根据角色id获取当前所拥有权限
///
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetRBACLists(int id)
{
return await _rBACServer.GetMenuByroleIdNew(id);
}
///
/// 根据角色id获取当前所拥有权限
///
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetRoleRightRBAC(int id, string MenuNo)
{
return await _rBACServer.GetRoleRightRBAC(MenuNo, UserId);
}
///
/// 根据角色id获取当前所拥有权限
///
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetRoleRightLists(int id)
{
return await _rBACServer.GetRoleRightList(id);
}
///
/// 获取角色权限信息列表
/// 多表:角色权限、角色、菜单
///
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetRoleRightList()
{
return await _roleRightServer.GetRoleMenuList();
}
///
/// 获取角色权限信息列表(单表)
///
/// 角色权限id
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetRoleRightOneListById(int id)
{
return await _roleRightServer.GetRoleRightOneListById(id);
}
///
/// 分配角色权限信息
///
/// 菜单号
/// 角色id
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task InsertRoleRight(string MenuNo, int id)
{
//根据Id获取角色号
SysRoles roles = await _rolesServer.GetRoleInfoById(id);
//保存角色权限信息
await _roleRightServer.InsertRoleRight(MenuNo, roles.RoleNo);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "角色权限",
FkNo = roles.RoleNo,
TypeName = "编辑",
Msg = "分配角色权限 角色号:" + roles.RoleNo
});
}
#endregion
#region 部门管理
///
/// 获取部门信息列表
///
/// 部门名称
/// 部门号
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetDepartmentList(string DepartmentName, string DepartmentNo)
{
return await _department.GetDepartmentList(DepartmentName, DepartmentNo);
}
///
/// 根据id获取部门信息
///
/// 部门id
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task GetDepartmentById(int id)
{
return await _department.GetDepartmentById(id);
}
///
/// 新增部门信息
///
/// 部门dto
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task AddDepartment(DepartmentDto departmentdto)
{
await _department.AddDepartment(departmentdto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "基础信息",
MenuName = "部门管理",
FkNo = departmentdto.DepartmentNo,
TypeName = "添加",
Msg = "添加部门信息 部门号:" + departmentdto.DepartmentNo
});
}
///
/// 删除部门信息
///
/// 部门id
///
/// 捕获异常
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task DelDepartment(int Id)
{
SysDepartment department = await _department.GetDepartmentById(Id);
await _department.DelDepartment(department);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "基础信息",
MenuName = "部门管理",
FkNo = department.DepartmentNo,
TypeName = "删除",
Msg = "删除部门信息 部门号:" + department.DepartmentNo
});
}
///
/// 编辑部门信息
///
/// 部门dto
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task ExitDepartment(DepartmentDto departmentdto)
{
await _department.ExitDepartment(departmentdto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "基础信息",
MenuName = "部门管理",
FkNo = departmentdto.DepartmentNo,
TypeName = "编辑",
Msg = "编辑部门信息 部门号:" + departmentdto.DepartmentNo
});
}
#endregion
#region 功能设定
///
/// 获取功能设定信息列表
///
/// 功能名称
/// 开启状态
/// 组号
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetFunSettingList(string FunSetName, string IsEnable, string GroupNo)
{
return await _setting.GetFunSettingList(FunSetName, IsEnable, GroupNo);
}
///
/// 根据id查询功能设定信息
///
/// 功能id
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task GetFunSettingById(int id)
{
return await _setting.GetFunSettingById(id);
}
///
/// 根据编号查询功能设定消息
///
/// 功能编号
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task GetFunSettingByNo(string funSetNo)
{
return await _setting.GetFunSettingByNo(funSetNo);
}
///
/// 新增功能信息
///
/// 功能设定dto
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task AddFunSettings(FunSettingDto settingdto)
{
await _setting.AddFunSettings(settingdto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "功能设定",
FkNo = settingdto.FunSetNo,
TypeName = "添加",
Msg = "添加功能设定 功能号:" + settingdto.FunSetNo
});
}
///
/// 删除功能信息
///
/// 功能id
///
/// 捕获异常
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task DelFunSettings(int id)
{
SysFunSetting funSetting = await _setting.GetFunSettingById(id);
await _setting.DelFunSettings(funSetting);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "功能设定",
FkNo = funSetting.FunSetNo,
TypeName = "删除",
Msg = "删除功能设定 功能号:" + funSetting.FunSetNo
});
}
///
/// 编辑功能信息
///
/// 功能设定dto
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task ExitFunSettings(FunSettingDto settingdto)
{
await _setting.ExitFunSettings(settingdto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "功能设定",
FkNo = settingdto.FunSetNo,
TypeName = "编辑",
Msg = "修改功能设定 功能号:" + settingdto.FunSetNo
});
}
#endregion
#region 物料管理
#region yyk
#region wms
///
/// 获取物料信息列表
///
/// 物料编码
/// 物料名称
/// 审核状态
/// 类型
/// 是否受控
/// 是否免检
/// 存储环境
/// 类别编码
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetMateList(string skuNo, string skuName, string auditStatusNo, string type, string isControlled, string isInspect, string environment, string categoryNo)
{
return await _mate.GetMateList(skuNo, skuName, auditStatusNo, type, isControlled, isInspect, environment, categoryNo);
}
///
/// 根据id查询物料信息
///
/// 物料id
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task GetMateById(int id)
{
return await _mate.GetMateById(id);
}
///
/// 新增物料信息
///
/// 物料dto
///
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task AddMate(MaterialsDto matedto)
{
await _mate.AddMate(matedto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "基础信息",
MenuName = "物料管理",
FkNo = matedto.SkuNo,
TypeName = "添加",
Msg = "添加物料信息 物料号:" + matedto.SkuNo
});
}
///
/// 删除物料信息
///
/// 物料id
///
/// 捕获异常
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task DelMate(int id)
{
SysMaterials mate = await _mate.GetMateById(id);
await _mate.DelMate(mate);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "基础信息",
MenuName = "物料管理",
FkNo = mate.SkuNo,
TypeName = "删除",
Msg = "删除物料信息 物料号:" + mate.SkuNo
});
}
///
/// 编辑物料信息
///
/// 物料dto
///
/// 捕获异常
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task ExitMate(MaterialsDto matedto)
{
await _mate.ExitMate(matedto);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "基础信息",
MenuName = "物料管理",
FkNo = matedto.SkuNo,
TypeName = "编辑",
Msg = "编辑物料信息 物料号:" + matedto.SkuNo
});
}
#region 包装 单位
///
/// 获取计量单位信息列表
///
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetUnitList()
{
return await _mate.GetUnitList();
}
///
/// 获取包装信息列表
///
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetPackagList()
{
return await _mate.GetPackagList();
}
#endregion
#endregion
#region erp
///
/// 获取erp数据
///
///
[HttpGet]
public IActionResult GetERPList()
{
List list = _mate.GetERPList();
return Ok(new
{
data = list,
msg = "成功",
code = 0
});
}
///
/// 根据id获取erp数据
///
///
[HttpGet]
public IActionResult GetERPListById(int id)
{
SysERPTest erp = _mate.GetERPListById(id);
return Ok(new
{
data = erp,
msg = "成功",
code = 0
});
}
///
/// 新增erp数据
///
/// erp测试dto
///
/// 捕获异常
[HttpPost]
public async Task AddERP(ERPTestDto erpdto)
{
//捕获异常
try
{
//获取当前操作用户id
var claimsIdentity = this.User.Identity as ClaimsIdentity;
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
int uid = Convert.ToInt32(userId);
//创建人
erpdto.CreateUser = uid;
//新增
int i = await _mate.AddERP(erpdto);
//判断是否新增成功
if (i == 0)
{
return Ok(new
{
data = i,
code = 1,
msg = "失败"
});
}
else if (i == 3)
{
return Ok(new
{
data = i,
code = 3,
msg = "物料号必须唯一"
});
}
else
{
return Ok(new
{
data = i,
code = 0,
msg = "成功"
});
}
}
catch (Exception ex)
{
//抛出异常
throw new Exception("新增erp异常", ex);
}
}
///
/// 删除erp信息
///
/// erp测试dto
///
/// 捕获异常
[HttpPost]
public async Task DelERP(ERPTestDto erpdto)
{
//捕获异常
try
{
//根据id获取数据
SysERPTest erp = _mate.GetERPListById(erpdto.Id);
// 获取当前操作用户id
var claimsIdentity = this.User.Identity as ClaimsIdentity;
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
int uid = Convert.ToInt32(userId);
erp.UpdateUser = uid;
//删除
int i = await _mate.DelERP(erp);
return i;
}
catch (Exception ex)
{
//抛出异常
throw new Exception("删除erp异常", ex);
}
}
///
/// 编辑erp数据
///
/// erp测试dto
///
/// 捕获异常
[HttpPost]
public async Task EditERP(ERPTestDto erpdto)
{
//捕获异常
try
{
//获取当前操作用户id
var claimsIdentity = this.User.Identity as ClaimsIdentity;
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
int uid = Convert.ToInt32(userId);
//创建人
erpdto.UpdateUser = uid;
//新增
int i = await _mate.EditERP(erpdto);
//判断是否编辑成功
if (i == 0)
{
return Ok(new
{
data = i,
code = 1,
msg = "失败"
});
}
else
{
return Ok(new
{
data = i,
code = 0,
msg = "成功"
});
}
}
catch (Exception ex)
{
//抛出异常
throw new Exception("编辑erp异常", ex);
}
}
#endregion
#endregion
#endregion
#region 客户管理
///
/// 查询客户信息
///
///
///
[HttpPost]
public IActionResult GetCustomerList(GetCustomerVm model)
{
try
{
var bolls = _customerSvc.GetCustomerList(model.CustomerNo, model.CustomerName, model.Type, model.LinkMan, model.Phone, model.Page, model.Limit, out int count);
return Ok(new { code = 0, count, msg = "客户信息", data = bolls });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 查询单条客户信息
///
///
///
[HttpPost]
public IActionResult GetCustomer(IdVm model)
{
try
{
var bolls = _customerSvc.GetCustomer(model.Id);
return Ok(new { code = 0, count = 0, msg = "客户信息", data = bolls });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 查询全部客户信息
///
///
[HttpGet]
public IActionResult GetCustomerSelect()
{
try
{
var bolls = _customerSvc.GetCustomerSelect();
return Ok(new { code = 0, count = 0, msg = "客户信息", data = bolls });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 添加客户信息
///
///
///
[HttpPost]
public IActionResult AddCustomer(AddCustomerVm model)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _customerSvc.AddCustomer(model.CustomerNo, model.CustomerName, model.Type, model.Address, model.LinkMan, model.Phone, model.BankAccount, model.CreditRating, model.Demo, int.Parse(userId));
if (bolls)
{
_operation.InsertOperation("基础信息", "客户管理", model.CustomerNo, "添加", "添加客户信息 客户号:" + model.CustomerNo, Convert.ToInt32(userId));
return Ok(new { code = 0, msg = "添加成功" });
}
else
{
return Ok(new { code = 1, msg = "添加失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 编辑客户信息
///
///
///
[HttpPost]
public IActionResult EditCustomer(EditCustomerVm model)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _customerSvc.EditCustomer(model.Id, model.CustomerNo, model.CustomerName, model.Type, model.Address, model.LinkMan, model.Phone, model.BankAccount, model.CreditRating, model.Demo, int.Parse(userId));
if (bolls)
{
_operation.InsertOperation("基础信息", "客户管理", model.CustomerNo, "编辑", "编辑客户信息 客户号:" + model.CustomerNo, Convert.ToInt32(userId));
return Ok(new { code = 0, msg = "编辑成功" });
}
else
{
return Ok(new { code = 1, msg = "编辑失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 删除客户信息
///
///
///
[HttpPost]
public IActionResult DelCustomer(IdVm model)
{
try
{
SysCustomer customer = _customerSvc.GetCustomer(model.Id);
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _customerSvc.DelCustomer(model.Id, int.Parse(userId));
if (bolls)
{
_operation.InsertOperation("基础信息", "客户管理", customer.CustomerNo, "删除", "删除客户信息 客户号:" + customer.CustomerNo, Convert.ToInt32(userId));
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = "删除失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 删除客户信息(多删除)
///
///
///
[HttpPost]
public IActionResult DelsCustomer(IdVm model)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _customerSvc.DelsCustomer(model.Ids, int.Parse(userId));
if (bolls)
{
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = "删除失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 物流信息管理
///
/// 查询物流信息
///
///
///
[HttpPost]
public IActionResult GetLogisticsInfoList(GetLogisticsInfoVm model)
{
try
{
var bolls = _logisticsSvc.GetLogisticsInfoList(model.CarrierName, model.LinkMan, model.Phone, model.LicensePlate, model.Type, model.Page, model.Limit, out int count);
return Ok(new { code = 0, count, msg = "物流信息", data = bolls });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 查询单条物流信息
///
///
///
[HttpPost]
public IActionResult GetLogisticsInfo(IdVm model)
{
try
{
var bolls = _logisticsSvc.GetLogisticsInfo(model.Id);
return Ok(new { code = 0, data = bolls });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 查询全部物流信息
///
///
[HttpGet]
public IActionResult GetLogisticsInfoSelect()
{
try
{
var bolls = _logisticsSvc.GetLogisticsInfoSelect();
return Ok(new { code = 0, data = bolls });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 添加物流信息
///
///
///
[HttpPost]
public IActionResult AddLogisticsInfo(AddLogisticsInfoVm model)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _logisticsSvc.AddLogisticsInfo(model, int.Parse(userId));
if (bolls)
{
_operation.InsertOperation("基础信息", "物流管理", model.CarrierName, "添加", "添加物流信息 公司名称:" + model.CarrierName, Convert.ToInt32(userId));
return Ok(new { code = 0, msg = "添加成功" });
}
else
{
return Ok(new { code = 1, msg = "添加失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 编辑物流信息
///
///
///
[HttpPost]
public IActionResult EditLogisticsInfo(EditLogisticsInfoVm model)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _logisticsSvc.EditLogisticsInfo(model, int.Parse(userId));
if (bolls)
{
_operation.InsertOperation("基础信息", "物流管理", model.CarrierName, "编辑", "编辑物流信息 公司名称:" + model.CarrierName, Convert.ToInt32(userId));
return Ok(new { code = 0, msg = "编辑成功" });
}
else
{
return Ok(new { code = 1, msg = "编辑失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 删除物流信息
///
///
///
[HttpPost]
public IActionResult DelLogisticsInfo(IdVm model)
{
try
{
SysLogisticsInfo logisit = _logisticsSvc.GetLogisticsInfo(model.Id);
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _logisticsSvc.DelLogisticsInfo(model.Id, int.Parse(userId));
if (bolls)
{
_operation.InsertOperation("基础信息", "物流管理", logisit.CarrierName, "删除", "删除物流信息 公司名称:" + logisit.CarrierName, Convert.ToInt32(userId));
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = "删除失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 删除物流信息(多条信息)
///
///
///
[HttpPost]
public IActionResult DelsLogisticsInfo(IdVm model)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _logisticsSvc.DelsLogisticsInfo(model.Ids, int.Parse(userId));
if (bolls)
{
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = "删除失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 计量单位管理
///
/// 查询计量单位信息
///
///
///
[HttpPost]
public IActionResult GetUnitList(GetUnitVm model)
{
try
{
var list = _unitSvc.GetUnitList(model.UnitNo, model.UnitName, model.Page, model.Limit, out int count);
return Ok(new { code = 0, count, msg = "物流信息", data = list });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 查询单条单位信息
///
///
///
[HttpPost]
public IActionResult GetUnit(IdVm model)
{
try
{
var data = _unitSvc.GetUnit(model.Id);
if (data != null)
{
return Ok(new { code = 0, data });
}
else
{
return Ok(new { code = 1, data = "未查询到物流信息" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 添加计量信息
///
///
///
[HttpPost]
public IActionResult AddUnit(AddEditUnitVm model)
{
if (ModelState.IsValid)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _unitSvc.AddUnit(model.UnitName, model.Abbrev, int.Parse(userId));
if (bolls)
{
return Ok(new { code = 0, msg = "添加成功" });
}
else
{
return Ok(new { code = 1, msg = "添加失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
else
{
return Ok(new { code = 1, msg = "数据格式错误" });
}
}
///
/// 编辑计量单位信息
///
///
///
[HttpPost]
public IActionResult EditUnit(AddEditUnitVm model)
{
if (ModelState.IsValid)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _unitSvc.EditUnit(model.Id, model.UnitName, model.Abbrev, int.Parse(userId));
if (bolls)
{
SysUnit unit = _unitSvc.GetUnit(model.Id);
_operation.InsertOperation("基础信息", "计量单位", unit.UnitNo, "编辑", "编辑计量单位 单位名称:" + unit.UnitNo, Convert.ToInt32(userId));
return Ok(new { code = 0, msg = "编辑成功" });
}
else
{
return Ok(new { code = 1, msg = "编辑失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
else
{
return Ok(new { code = 1, msg = "数据格式错误" });
}
}
///
/// 删除计量单位信息
///
///
///
[HttpPost]
public IActionResult DelUnit(IdVm model)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _unitSvc.DelUnit(model.Id, int.Parse(userId));
if (bolls)
{
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = "删除失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 删除计量单位信息(多删除)
///
///
///
[HttpPost]
public IActionResult DelsUnit(IdVm model)
{
try
{
//获取当前登录的用户ID
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(userId))
{
return Ok(new { code = 1, msg = "为获取到当前操作人信息" });
}
var bolls = _unitSvc.DelsUnit(model.Ids, int.Parse(userId));
if (bolls)
{
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = "删除失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 包装管理
private string UserId;
//public BasisController()
//{
// var claimsIdentity = this.User.Identity as ClaimsIdentity;
// if (claimsIdentity == null)
// {
// throw new Exception("未获取到用户信息");
// }
// UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
// if (string.IsNullOrWhiteSpace(UserId))
// {
// throw new Exception("未获取到用户信息");
// }
//}
///
/// 查询包装信息
///
///
///
[HttpPost]
public IActionResult GetPackagList(GetPackagVm model)
{
try
{
var list = _packagSvc.GetPackagList(model.PackagNo, model.PackagName, model.Level, model.Page, model.Limit, out int count);
return Ok(new { code = 0, count, msg = "物流信息", data = list });
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 根据id获取包装信息
///
/// 包装id
///
[HttpGet]
public IActionResult GetPackagById(int id)
{
SysPackag packag = _packagSvc.GetPackagById(id);
return Ok(new
{
data = packag,
code = 0,
msg = "成功"
});
}
///
/// 添加包装信息
///
/// 包装信息
///
[HttpPost]
public IActionResult AddPackag(AddEditPackagVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
model.CreateUser = int.Parse(UserId);
int i = _packagSvc.AddPackag(model);
if (i == 1)
{
_operation.InsertOperation("基础信息", "包装管理", model.PackagNo, "添加", "添加包装信息 包装编号:" + model.PackagNo, Convert.ToInt32(UserId));
return Ok(new { code = 0, msg = "添加成功" });
}
else if (i > 1)
{
return Ok(new { code = i, msg = "包装等级不可越级添加" });
}
else
{
return Ok(new { code = 1, msg = "添加失败" });
}
}
catch (Exception e)
{
return Ok(new
{
code = 1,
msg = e.Message
});
}
}
///
/// 编辑包装信息
///
/// 包装信息
///
[HttpPost]
public IActionResult EditPackag(AddEditPackagVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
model.CreateUser = int.Parse(UserId);
int i = _packagSvc.EditPackag(model);
if (i == 1)
{
_operation.InsertOperation("基础信息", "包装管理", model.PackagNo, "编辑", "编辑包装信息 包装编号:" + model.PackagNo, Convert.ToInt32(UserId));
return Ok(new { code = 0, msg = "编辑成功" });
}
if (i == 2)
{
return Ok(new { code = i, msg = "包装等级不可越级修改 请重新输入" });
}
else
{
return Ok(new { code = 1, msg = "编辑失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
///
/// 逻辑删除包装信息
///
///
///
[HttpPost]
public IActionResult DelPackag(AddEditPackagVm model)
{
try
{
var claimsIdentity = this.User.Identity as ClaimsIdentity;
if (claimsIdentity == null)
{
throw new Exception("未获取到用户信息");
}
UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
if (string.IsNullOrWhiteSpace(UserId))
{
throw new Exception("未获取到用户信息");
}
var bolls = _packagSvc.DelPackag(model.Id, int.Parse(UserId));
if (bolls)
{
_operation.InsertOperation("基础信息", "包装管理", model.PackagNo, "删除", "删除包装信息 包装编号:" + model.PackagNo, Convert.ToInt32(UserId));
return Ok(new { code = 0, msg = "删除成功" });
}
else
{
return Ok(new { code = 1, msg = "删除失败" });
}
}
catch (Exception e)
{
return Ok(new { code = 1, msg = e.Message });
}
}
#endregion
#region 系统操作日志
///
/// 获取操作日志信息列表
///
///
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetSysOperationList(GetOperationVm model)
{
return await _operation.GetSysOperationList(model);
}
///
/// 获取类型菜单
///
/// 字典名称
///
[HttpGet]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetDicTypeList(string dicName)
{
return await _operation.GetDicTypeList(dicName);
}
#endregion
#region 接口管理
///
/// 获取接口列表
///
///
///
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetInterfaceList(InterfaceVm model)
{
return await _interface.GetInterfaceList(model);
}
///
/// 获取接口明细列表
///
///
///
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
public async Task> GetInterfaceDetailList(InterfaceDetailVm model)
{
return await _interface.GetInterfaceDetailList(model);
}
///
/// 添加接口信息
///
///
///
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task AddInterface(InterfaceVm model)
{
await _interface.AddInterface(model);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "接口管理",
FkNo = model.InterfaceNo,
TypeName = "添加",
Msg = $"添加了接口编号为{model.InterfaceNo}的接口信息"
});
}
///
/// 编辑接口信息
///
///
///
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task EditInterface(InterfaceVm model)
{
await _interface.EditInterface(model);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "接口管理",
FkNo = model.InterfaceNo,
TypeName = "编辑",
Msg = $"编辑了接口编号为{model.InterfaceNo}的接口信息"
});
}
///
/// 删除接口信息
///
///
///
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task DelInterface(InterfaceVm model)
{
await _interface.DelInterface(model);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "接口管理",
FkNo = model.InterfaceNo,
TypeName = "编辑",
Msg = $"删除了接口编号为{model.InterfaceNo}的接口信息"
});
}
///
/// 删除接口明细信息
///
///
///
[HttpPost]
[ServiceFilter(typeof(ApiResponseActionFilter))]
[UnitOfWork]
public async Task DelInterfaceDetail(InterfaceDetailVm model)
{
await _interface.DelInterfaceDetail(model);
await _operation.InsertOperation(new OperationInputVm()
{
ParentName = "系统设置",
MenuName = "接口管理",
FkNo = model.InterfaceNo,
TypeName = "编辑",
Msg = $"删除了接口编号为{model.InterfaceNo}的接口信息,本系统字段为{model.Field}的接口信息"
});
}
#endregion
}
}