335 lines
13 KiB
C#
Executable File
335 lines
13 KiB
C#
Executable File
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Newtonsoft.Json.Linq;
|
|
using Opsoft.Data;
|
|
using Opsoft.NetCore.O3App.Domain;
|
|
using Opsoft.NetCore.O3App.Domain.Enums.ReportCodes;
|
|
using Opsoft.NetCore.O3App.Domain.Interface;
|
|
using Opsoft.NetCore.O3App.Domain.Models;
|
|
using Opsoft.NetCore.O3App.Domain.UnitOfWork.BaseData.IRepositories;
|
|
using Opsoft.NetCore.O3App.Domain.UnitOfWork.BaseData.IServices;
|
|
using Opsoft.NetCore.O3App.Domain.UnitOfWork.BaseData.Model;
|
|
using Opsoft.NetCore.O3App.Domain.UnitOfWork.IPadReport.Model;
|
|
using Opsoft.NetCore.O3App.Services.CommonFunction;
|
|
using Opsoft.NetCore.O3App.Shared;
|
|
using Opsoft.NetCore.O3App.Shared.Utils;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Opsoft.NetCore.O3App.Services.BaseData
|
|
{
|
|
[MapTo(typeof(ISysConfigDataService), ServiceLifetime.Transient)]
|
|
public class SysConfigDataService : ServiceBase<BaseEntity, ISysConfigDataRepository>, ISysConfigDataService
|
|
{
|
|
private IMemoryCache _cache;
|
|
|
|
public SysConfigDataService(ISysConfigDataRepository repository, IMemoryCache memoryCache) : base(repository)
|
|
{
|
|
Init(repository);
|
|
_cache = memoryCache;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取APK版本
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<TBdAppversion> GetLatestAppInfo(int apkTypeD)
|
|
{
|
|
return await (repository as ISysConfigDataRepository).GetLatestAppInfo(apkTypeD);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取仓位信息
|
|
/// </summary>
|
|
/// <param name="paramaters"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<BD_FLEXVALUES>> GetAllFlexValues(Dictionary<string, string> paramaters)
|
|
{
|
|
List<T_BD_STOCK> tempStockData = await GetAllStock(paramaters);
|
|
if (!tempStockData[0].FISOPENLOCATION)
|
|
{
|
|
throw new O3AppException("该仓库没有启用仓位管理", 700);
|
|
}
|
|
string fInterID = tempStockData[0].FINTERID;
|
|
List<BD_FLEXVALUES> reFlexValuesList = await (repository as ISysConfigDataRepository).GetAllFlexValues(fInterID);
|
|
return reFlexValuesList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取轮播图信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<T_BAS_IMAGEPAGEVIEW>> GetAllImagePageView()
|
|
{
|
|
return await (repository as ISysConfigDataRepository).GetAllImagePageView();
|
|
}
|
|
/// <summary>
|
|
/// 获取个人日志信息
|
|
/// </summary>
|
|
/// <param name="paramaters"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<T_BD_PERSONDIARY>> GetAllPersonDiary(Dictionary<string, string> paramaters)
|
|
{
|
|
string dateTime = string.Empty;
|
|
string fInterID = string.Empty;
|
|
if (paramaters.ContainsKey("dateTime"))
|
|
{
|
|
dateTime = paramaters["dateTime"].ToString();
|
|
if (!CheckDateTime.IsDate(dateTime))
|
|
{
|
|
throw new O3AppException("传参信息错误,非时间类型", 600);
|
|
}
|
|
}
|
|
List<T_BD_PERSONDIARY> retData = await (repository as ISysConfigDataRepository).GetAllPersonDiary(dateTime, fInterID);
|
|
if (retData.Count <= 0)
|
|
{
|
|
throw new O3AppException("未找到日志信息", 700);
|
|
}
|
|
return retData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取仓库信息
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<T_BD_STOCK>> GetAllStock(Dictionary<string, string> paramaters)
|
|
{
|
|
//判断参数是否符合条件
|
|
if (!paramaters.ContainsKey("stockNumber") || !paramaters.ContainsKey("orgid"))
|
|
{
|
|
throw new O3AppException("传参信息错误,未定义", 400);
|
|
}
|
|
if (string.IsNullOrEmpty(paramaters["stockNumber"].ToString()))
|
|
{
|
|
throw new O3AppException("传参信息错误,仓库代码信息为空", 600);
|
|
}
|
|
//查询数据库
|
|
List<T_BD_STOCK> retData = await (repository as ISysConfigDataRepository).GetAllStock(paramaters);
|
|
//判断查询结果
|
|
if (retData.Count <= 0)
|
|
{
|
|
throw new O3AppException("仓库信息未找到", 700);
|
|
}
|
|
return retData;
|
|
}
|
|
/// <summary>
|
|
/// 编辑个人日志信息
|
|
/// </summary>
|
|
/// <param name="paramaters"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<T_BD_PERSONDIARY>> UpdatePersonDiary(T_BD_PERSONDIARY diary)
|
|
{
|
|
List<T_BD_PERSONDIARY> retData = await (repository as ISysConfigDataRepository).UpDatePersonDiary(diary);
|
|
return retData;
|
|
}
|
|
|
|
public async Task<string> DeletePersonDiary(string interId)
|
|
{
|
|
var retData = await (repository as ISysConfigDataRepository).DeletePersonDiary(interId);
|
|
return retData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取个人事项
|
|
/// </summary>
|
|
/// <param name="paramaters"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<T_BD_PERSONALMATTERS>> GetAllPersonalMatters()
|
|
{
|
|
List<T_BD_PERSONALMATTERS> retData = await (repository as ISysConfigDataRepository).GetAllPersonalMatters();
|
|
//获取查询结果
|
|
if (retData.Count <= 0)
|
|
{
|
|
throw new O3AppException("未找到个人事项信息", 700);
|
|
}
|
|
return retData;
|
|
}
|
|
/// <summary>
|
|
/// 编辑个人事项返回
|
|
/// </summary>
|
|
/// <param name="paramaters"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<T_BD_PERSONALMATTERS>> UpdatePersonalMatters(JObject data)
|
|
{
|
|
//判断参数是否符合条件
|
|
if (!data.ContainsKey("FINFO") || !data.ContainsKey("FPERSONALDATE"))
|
|
{
|
|
throw new O3AppException("传参信息错误", 400);
|
|
}
|
|
List<T_BD_PERSONALMATTERS> retData = await (repository as ISysConfigDataRepository).UpdatePersonalMatters(data);
|
|
return retData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询基本信息服务实现
|
|
/// </summary>
|
|
/// <param name="paramaters"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<Basic>> QueryALLResource(Dictionary<string, string> paramaters)
|
|
{
|
|
#region 参数验证
|
|
//查询的数据类型
|
|
if (!paramaters.ContainsKey("basicType"))
|
|
{
|
|
throw new O3AppException("【数据类型】传参信息错误,未定义", 400);
|
|
}
|
|
//判断数据类型以及值是否符合要求
|
|
if (!int.TryParse(paramaters["basicType"].ToString(), out int basicType) || !Enum.IsDefined(typeof(BasicTableName), basicType))
|
|
{
|
|
throw new O3AppException("【数据类型】传参类型错误,值设定有误", 400);
|
|
}
|
|
#endregion
|
|
|
|
#region 数据获取
|
|
//缓存名称
|
|
//string cacheName = LoginInfo.DBAias + (BasicTableName)basicType;
|
|
//判断缓存中是否有值
|
|
//if (!_cache.TryGetValue(cacheName, out List<Basic> listFata))
|
|
//{
|
|
// listFata = await (repository as ISysConfigDataRepository).QueryALLResource(paramaters);
|
|
// //基本资料记录缓存10分钟
|
|
// _cache.Set(cacheName, listFata, TimeSpan.FromMinutes(10));
|
|
//}
|
|
////判断是否传入了编号
|
|
//if (!paramaters["basicNO"].IsNullOrEmpty())
|
|
//{
|
|
// return listFata.Where(o=>o.FNO == paramaters["basicNO"].ToString()).ToList();
|
|
//}
|
|
//else
|
|
//{
|
|
// return listFata;
|
|
//}
|
|
return await (repository as ISysConfigDataRepository).QueryALLResource(paramaters);
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户信息
|
|
/// </summary>
|
|
/// <param name="paramaters"></param>
|
|
/// <returns></returns>
|
|
public async Task<LoginRequest> QueryLoginUserInfo(string useNO)
|
|
{
|
|
if (useNO == null || useNO.ToString() == "")
|
|
{
|
|
throw new O3AppException("用户信息传参错误!!");
|
|
}
|
|
return await (repository as ISysConfigDataRepository).QueryLoginUserInfo(useNO);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取系统打印参数
|
|
/// </summary>
|
|
/// <param name="SData"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<SysPrintData>> SysPrintIteam(SysPrintIteam data)
|
|
{
|
|
if (data.PrgKey == null || data.PrgKey.ToString() == "")
|
|
{
|
|
throw new O3AppException("单据信息传参错误!!");
|
|
}
|
|
return await (repository as ISysConfigDataRepository).SysPrintIteam(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取蓝牙打印机信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<Basic>> SysPrintBluetooth(SysPrintIteam data)
|
|
{
|
|
if (data.PrgKey == null || data.PrgKey.ToString() == "")
|
|
{
|
|
throw new O3AppException("单据信息传参错误!!");
|
|
}
|
|
return await (repository as ISysConfigDataRepository).SysPrintBluetooth(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上传图片
|
|
/// </summary>
|
|
/// <param name="file"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> Upload(IFormFile file)
|
|
{
|
|
using APPServerContext context = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID);
|
|
if (file == null)
|
|
{
|
|
throw new O3AppException("上传文件为空!!", 400);
|
|
}
|
|
string webRootPath = Directory.GetCurrentDirectory();
|
|
string uploadPath = Path.Combine("OpsoftTemp", DateTime.Now.ToString("yyyyMMdd"));
|
|
string urlpath = "OpsoftTemp" + "/" + DateTime.Now.ToString("yyyyMMdd");
|
|
string dirPath = Path.Combine(webRootPath, uploadPath);
|
|
if (!Directory.Exists(dirPath))
|
|
{
|
|
Directory.CreateDirectory(dirPath);
|
|
}
|
|
string fileExt = Path.GetExtension(file.FileName).Trim('.');//文件扩展名,不含"."
|
|
string newFileName = Guid.NewGuid().ToString().Replace("-", "") + "." + fileExt;//生成新的文件名称
|
|
var filePath = Path.Combine(dirPath, newFileName);
|
|
|
|
using (var stream = new FileStream(filePath, FileMode.Create))
|
|
{
|
|
await file.CopyToAsync(stream);
|
|
}
|
|
|
|
//文件下载绝对路径
|
|
string fileAbsoluteDownPath = $@"{Directory.GetCurrentDirectory()}\{uploadPath}\{newFileName}";
|
|
//相对路径
|
|
string fileRelativeDownPath = $@"{GetCompleteUrl()}/{uploadPath}/{newFileName}";
|
|
//上传服务器IP地址
|
|
string serverIP = context.Database.SqlQueryString("SELECT FVALUE FROM SYS_DEPARAMETERS WHERE FNUMBER = 'FileServerUrl' ");
|
|
//获取系统配置
|
|
Hashtable PBCursor = context.PBValue("EQPICUpload,C,;");
|
|
//图片所在文件夹路径
|
|
string FilePath = PBCursor["EQPICUpload"].ToStringEx();
|
|
//判断文件是否已经存在了
|
|
if (File.Exists(fileAbsoluteDownPath))
|
|
{
|
|
if (serverIP.IsNullOrEmpty())
|
|
{
|
|
serverIP = "http://127.0.0.1";
|
|
}
|
|
|
|
FileUpDownInfo myUpInfo = new FileUpDownInfo()
|
|
{
|
|
SourceFileName = newFileName,
|
|
SourceFilePath = $@"{Directory.GetCurrentDirectory()}\{uploadPath}",
|
|
TargetFileName = newFileName,
|
|
TargetFilePath = Path.Combine(FilePath, uploadPath),
|
|
ServerIP = serverIP
|
|
};
|
|
//上传图片
|
|
FileHelper.WebUpLoadFile(myUpInfo);
|
|
}
|
|
int firstLong = FilePath.IndexOf(@"\");
|
|
int lastLong = FilePath.LastIndexOf(@"\");
|
|
string fileCut = FilePath.Substring(firstLong + 1, lastLong - firstLong - 1);
|
|
string url = $@"{serverIP}/{fileCut}/{urlpath}/{newFileName}";
|
|
return await Task.Run(() => url);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前请求完整的Url地址 q
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string GetCompleteUrl()
|
|
{
|
|
return new StringBuilder()
|
|
.Append(Context.Request.Scheme)
|
|
.Append("://")
|
|
.Append(Context.Request.Host)
|
|
.Append(Context.Request.PathBase)
|
|
.ToString();
|
|
}
|
|
}
|
|
}
|