فهرست منبع

Merge branch 'master' of http://111.198.38.3:3000/365wy/dccloud

shengxuefei 4 سال پیش
والد
کامیت
57e95bc77e

+ 31 - 0
WebAPIBase.NetCore/Utils/ApiResponse.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebAPIBase.Utils
+{
+    /// <summary>
+    /// api接口统一返回数据
+    /// </summary>
+    public class ApiResponse
+    {
+        /// <summary>
+        /// 是否成功
+        /// </summary>
+        public bool isSuccess { get; set; }
+        /// <summary>
+        /// 提示信息
+        /// </summary>
+        public string message { get; set; }
+        /// <summary>
+        /// 状态码
+        /// </summary>
+        public int code { get; set; }
+        /// <summary>
+        /// 返回查询接口的数据
+        /// </summary>
+        public Object returnData { get; set; }
+    }
+}

+ 23 - 26
WebAPIBase.NetCore/Utils/CustomErrorMiddleware.cs

@@ -7,48 +7,45 @@ using System.Text;
 using System.Threading.Tasks;
 using NLog;
 using NLog.Web.AspNetCore;
+using System.Net;
+using Newtonsoft.Json;
+using Microsoft.AspNetCore.Builder;
 
 namespace WebAPIBase.Utils
 {
-    public class CustomErrorMiddleware : ICustomErrorMiddleware
+    public class CustomErrorMiddleware
     {
-        private readonly RequestDelegate next;
-        private IHostingEnvironment environment;
-
-        //Nlog构造方法注入
-        private readonly Microsoft.Extensions.Logging.ILogger<CustomErrorMiddleware> _logger;
-        public CustomErrorMiddleware(RequestDelegate next, IHostingEnvironment environment, Microsoft.Extensions.Logging.ILogger<CustomErrorMiddleware> logger)
+        private readonly RequestDelegate _next;
+        private static Logger logger = LogManager.GetCurrentClassLogger();
+        public CustomErrorMiddleware(RequestDelegate next)
         {
-            _logger = logger;
-            this.next = next;
-            this.environment = environment;
+            _next = next;
         }
 
-        public async Task Invoke(HttpContext context)
+        public async Task Invoke(HttpContext httpContext)
         {
             try
             {
-                await next.Invoke(context);
-                var features = context.Features;
+                await _next(httpContext);
             }
-            catch (Exception e)
+            catch (Exception ex)
             {
-                await HandleException(context, e);
+                logger.Error(ex);
+                httpContext.Response.StatusCode = 200;
+                var result = JsonConvert.SerializeObject(new ApiResponse { isSuccess = false, message = ex.Message + "\r\n" + ex.StackTrace, code = 500 });
+                httpContext.Response.ContentType = "application/json; charset=utf-8";
+                await httpContext.Response.WriteAsync(result);
+                //throw;
             }
         }
 
-        private async Task HandleException(HttpContext context, Exception ex)
-        {
-
-            //_logger.Log();
-
-            await context.Response.WriteAsync(ex.Message + "\r\n" + ex.StackTrace);
-        }
-
-        public void LogError(Exception ex)
+    }
+    // Extension method used to add the middleware to the HTTP request pipeline.
+    public static class CustomErrorMiddlewareExtensions
+    {
+        public static IApplicationBuilder UseCustomErrorMiddleware(this IApplicationBuilder builder)
         {
-
-            // _logger.Log();
+            return builder.UseMiddleware<CustomErrorMiddleware>();
         }
     }
 }

+ 165 - 0
WebAPIBase.NetCore/Utils/Encrypt.cs

@@ -0,0 +1,165 @@
+using System;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+namespace WebAPIBase.Utils
+{
+    public partial class StringHelper
+    {
+
+
+        /// <summary>
+        /// 中英文加密
+        /// </summary>
+        /// <param name="instr">要加密的字体串</param>
+        /// <returns></returns>
+        public static string EncryptMD5(string instr)
+        {
+            string result;
+            try
+            {
+                byte[] toByte = Encoding.Default.GetBytes(instr);
+                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
+                toByte = md5.ComputeHash(toByte);
+                result = BitConverter.ToString(toByte).Replace("-", "");
+            }
+            catch
+            {
+                result = string.Empty;
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// 指定字节流编码计算MD5哈希值,可解决不同系统中文编码差异的问题。
+        /// </summary>
+        /// <param name="source">要进行哈希的字符串</param>
+        /// <param name="bytesEncoding">获取字符串字节流的编码,如果是中文,不同系统之间务必请使用相同编码</param>
+        /// <returns>32位大写MD5哈希值</returns>
+        public static string ComputeMD5(string source, Encoding bytesEncoding)
+        {
+            byte[] sourceBytes = bytesEncoding.GetBytes(source);
+
+            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
+
+            byte[] hashedBytes = md5.ComputeHash(sourceBytes);
+
+            StringBuilder buffer = new StringBuilder(hashedBytes.Length);
+            foreach (byte item in hashedBytes)
+            {
+                buffer.AppendFormat("{0:X2}", item);
+            }
+
+            return buffer.ToString();
+        }
+
+        #region 加密解密,可以设置密钥
+        /// <summary>
+        /// 可以设置密钥的加密方式
+        /// </summary>
+        /// <param name="sourceData">原文</param>
+        /// <param name="key">密钥,8位数字,字符串方式</param>
+        /// <returns></returns>
+        public static string Encrypt(string sourceData, string key)
+        {
+            #region 检查密钥是否符合规定
+            if (key.Length > 8)
+            {
+                key = key.Substring(0, 8);
+            }
+            #endregion
+
+            Byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
+
+            Byte[] keys = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, key.Length));
+            try
+            {
+                //convert data to byte array
+                Byte[] sourceDataBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(sourceData);
+                //get target memory stream
+                MemoryStream tempStream = new MemoryStream();
+                //get encryptor and encryption stream
+                DESCryptoServiceProvider encryptor = new DESCryptoServiceProvider();
+                CryptoStream encryptionStream = new CryptoStream(tempStream, encryptor.CreateEncryptor(keys, iv), CryptoStreamMode.Write);
+
+                //encrypt data
+                encryptionStream.Write(sourceDataBytes, 0, sourceDataBytes.Length);
+                encryptionStream.FlushFinalBlock();
+
+                //put data into byte array
+                Byte[] encryptedDataBytes = tempStream.GetBuffer();
+                //convert encrypted data into string
+                return System.Convert.ToBase64String(encryptedDataBytes, 0, (int)tempStream.Length);
+            }
+            catch (Exception ex)
+            {
+                throw (ex);
+            }
+        }
+
+        /// <summary>
+        /// 根据知道的密钥解密
+        /// </summary>
+        /// <param name="sourceData">密文</param>
+        /// <param name="key">密钥,8位数字,字符串方式</param>
+        /// <returns></returns>
+        public static string Decrypt(string sourceData, string key)
+        {
+            #region 检查密钥是否符合规定
+            if (key.Length > 8)
+            {
+                key = key.Substring(0, 8);
+            }
+            #endregion
+
+
+            Byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
+            Byte[] keys = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, key.Length));
+            try
+            {
+                Byte[] encryptedDataBytes = System.Convert.FromBase64String(sourceData);
+                using (MemoryStream tempStream = new MemoryStream(encryptedDataBytes, 0, encryptedDataBytes.Length))
+                {
+                    using (DESCryptoServiceProvider decryptor = new DESCryptoServiceProvider())
+                    {
+                        using (
+                            CryptoStream decryptionStream = new CryptoStream(tempStream,
+                                decryptor.CreateDecryptor(keys, iv), CryptoStreamMode.Read))
+                        {
+                            using (StreamReader allDataReader = new StreamReader(decryptionStream))
+                            {
+                                return allDataReader.ReadToEnd();
+                            }
+
+                        }
+
+                    }
+
+                }
+
+            }
+            catch (Exception ex)
+            {
+                throw;
+            }
+        }
+        #endregion
+
+
+        [Obsolete("方法名写错了,请用ASP16MD5", false)]
+        public static string ASP18MD5(string instr)
+        {
+            return EncryptMD5(instr).Substring(8, 16).ToLower();
+        }
+
+        /// <summary>
+        /// 16位md5加密,返回小写
+        /// </summary>
+        /// <param name="instr">要加密的字体串</param>
+        /// <returns></returns>
+        public static string ASP16MD5(string instr)
+        {
+            return EncryptMD5(instr).Substring(8, 16).ToLower();
+        }
+    }
+}

+ 300 - 0
WebAPIBase.NetCore/Utils/ExtensionMethod.cs

@@ -0,0 +1,300 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebAPIBase.Utils
+{
+    public static partial class ExtensionMethod
+    {
+
+
+
+        #region string判断扩展
+        public static bool IsNullOrEmpty(this string str)
+        {
+            return StringHelper.IsNullOrEmpty(str);
+        }
+
+        public static bool IsNotNullAndEmpty(this string str)
+        {
+            return StringHelper.IsNotNullAndEmpty(str);
+        }
+
+        /// <summary>
+        /// 判断是否是整数
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsInteger(this string str)
+        {
+            return StringHelper.IsInteger(str);
+        }
+
+        /// <summary>
+        /// 判断字符串是否是正整数,可以是无数位
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsPositiveInteger(this string str)
+        {
+            return StringHelper.IsPositiveInteger(str);
+        }
+        /// <summary>
+        /// 判断是否为decimal类型
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsDecimal(this string str)
+        {
+            return StringHelper.IsDecimal(str);
+        }
+
+        public static bool IsNumber(this string str)
+        {
+            return StringHelper.IsNumber(str);
+        }
+
+        /// <summary>
+        /// 判断是否为手机号
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsCellPhone(this string str)
+        {
+            return StringHelper.IsCellPhone(str);
+        }
+        /// <summary>
+        /// 是否固定电话
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsPhone(this string str)
+        {
+            return StringHelper.IsPhone(str);
+        }
+        /// <summary>
+        /// 判断是否为邮箱地址
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsEmail(this string str)
+        {
+            return StringHelper.IsEmail(str);
+        }
+        /// <summary>
+        /// 判断身份证号格式是否正确
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsIDCard(this string str)
+        {
+            return StringHelper.IsIDCard(str);
+        }
+        #endregion
+
+
+        #region object 判断扩展
+        /// <summary>
+        /// 是null或空
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public static bool IsNullOrEmpty(this object obj)
+        {
+            return obj == null ? true : StringHelper.IsNullOrEmpty(obj.ToString());
+        }
+
+        public static bool IsNotNullAndEmpty(this object obj)
+        {
+            return obj == null ? false : StringHelper.IsNotNullAndEmpty(obj.ToString());
+        }
+        public static bool IsInteger(this object obj)
+        {
+            return obj == null ? false : StringHelper.IsInteger(obj.ToString());
+        }
+        public static bool IsDecimal(this object obj)
+        {
+            return obj == null ? false : StringHelper.IsDecimal(obj.ToString());
+        }
+
+
+        public static bool IsNumber(this object obj)
+        {
+            return obj == null ? false : StringHelper.IsNumber(obj.ToString());
+        }
+
+        /// <summary>
+        /// 对象转换为字符串,如果对象为null,则为空
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public static string SConvertString(this object obj)
+        {
+            return StringHelper.SConvertString(obj);
+        }
+
+        public static DataSet ToDataSet<T>(this IList<T> list)
+        {
+            Type elementType = typeof(T);
+            var ds = new DataSet();
+            var t = new DataTable();
+            ds.Tables.Add(t);
+            elementType.GetProperties().ToList().ForEach(propInfo => t.Columns.Add(propInfo.Name, Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType));
+            foreach (T item in list)
+            {
+                var row = t.NewRow();
+                elementType.GetProperties().ToList().ForEach(propInfo => row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value);
+                t.Rows.Add(row);
+            }
+            return ds;
+        }
+
+        #endregion
+
+        #region 转换扩展
+        /// <summary>
+        /// 转换为int32类型,若是非数值型字串,则变为默认值0
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static int ToInteger(this object str)
+        {
+            try
+            {
+                return Convert.ToInt32(str);
+            }
+            catch
+            {
+                return 0;
+            }
+        }
+        /// <summary>
+        /// 转换为Double类型,若是非数值型字串,则变为默认值0
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static double ToNumber(this object str)
+        {
+            try
+            {
+                return Convert.ToDouble(str);
+            }
+            catch
+            {
+                return 0;
+            }
+        }
+
+        /// <summary>
+        /// 转换为Decimal类型,若是非数值型字串,则变为默认值0
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static decimal ToDecimal(this object str)
+        {
+
+            try
+            {
+                return Convert.ToDecimal(str);
+            }
+            catch
+            {
+                return 0;
+            }
+
+        }
+
+        public static DateTime ToDateTime(this string str)
+        {
+            return DateTime.Parse(str);
+        }
+        public static string FormatWith(this string str, params object[] objs)
+        {
+            return string.Format(str, objs);
+        }
+        /// <summary>
+        /// 首字母小写
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        /// 
+        public static string ToCamel(this string str)
+        {
+            if (str.IsNullOrEmpty())
+            {
+                return str;
+            }
+            else
+            {
+                if (str.Length > 1)
+                {
+                    return str[0].ToString().ToLower() + str.Substring(1);
+                }
+                else
+                {
+                    return str.ToLower();
+                }
+            }
+        }
+        /// <summary>
+        ///首字母大写
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static string ToPascal(this string str)
+        {
+            if (str.IsNullOrEmpty())
+            {
+                return str;
+            }
+            else
+            {
+                if (str.Length > 1)
+                {
+                    return str[0].ToString().ToUpper() + str.Substring(1);
+                }
+                else
+                {
+                    return str.ToLower();
+                }
+            }
+        }
+
+        /// <summary>
+        /// 得到大写
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static string To32MD5(this string str)
+        {
+            return StringHelper.EncryptMD5(str);
+        }
+        /// <summary>
+        /// 得到小写
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static string To16MD5(this string str)
+        {
+            return StringHelper.ASP16MD5(str);
+        }
+
+        #endregion
+
+        #region 拼音
+
+        public static string ToChineseSpell(this string str)
+        {
+            return StringHelper.GetChineseSpell(str);
+        }
+        public static string ToChineseIndex(this string str)
+        {
+            return StringHelper.GetChineseIndex(str);
+        }
+        #endregion
+
+    }
+}

+ 35 - 0
WebAPIBase.NetCore/Utils/StringCommon.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebAPIBase.Utils
+{
+    internal class StringCommon
+    {
+        /// <summary>
+        /// 邮箱正则表达式
+        /// </summary>
+        public static readonly string RegEmail = @"^[-_A-Za-z0-9\.]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$";
+        public static readonly string RegEmailNoEnds = @"[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}";
+
+        /// <summary>
+        /// 固话号正则表达式
+        /// </summary>
+        public static readonly string RegTelephone = "^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$";
+        public static readonly string RegTelephoneNoEnds = "(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?";
+
+        /// <summary>
+        /// 手机号正则表达式
+        /// </summary>
+        public static readonly string RegCellphone = @"^(13[0-9]|15[0-9]|18[0-9]|17[0-9]|147)\d{8}$";
+        public static readonly string RegCellphoneNoEnds = @"(13[0-9]|15[0-9]|18[0-9]|147)\d{8}";
+
+
+        /// <summary>
+        /// ip地址表达式
+        /// </summary>
+        public static readonly string RegIp = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";
+    }
+}

+ 524 - 0
WebAPIBase.NetCore/Utils/StringHelper.cs

@@ -0,0 +1,524 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace WebAPIBase.Utils
+{
+    public partial class StringHelper
+    {
+        #region 判断
+
+        /// <summary>
+        /// 判断字符串是否在一个以‘_ , |’隔开的字符串里
+        /// </summary>
+        /// <param name="str">目标字符串</param>
+        /// <param name="strs">要查找的字符串</param>
+        /// <returns></returns>
+        public static bool IsInStrs(string str, string strs)
+        {
+            return IsInParams(str, strs.Split('_', ',', '|'));
+        }
+
+        /// <summary>
+        /// 判断字符串是否在一个数组里
+        /// </summary>
+        /// <param name="str">目标字符串</param>
+        /// <param name="strs">要查找的字符串数组</param>
+        /// <returns></returns>
+        public static bool IsInParams(string str, params string[] strs)
+        {
+            foreach (string s in strs)
+            {
+                if (s == str)
+                    return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 是否是null或空字符串
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsNullOrEmpty(string str)
+        {
+            return string.IsNullOrEmpty(str);
+        }
+
+        /// <summary>
+        /// 是否不为空字符串也不是null
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsNotNullAndEmpty(string str)
+        {
+            return !string.IsNullOrEmpty(str);
+        }
+
+
+
+        /// <summary>
+        /// 转换为字符串
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <returns></returns>
+        public static string SConvertString(object o)
+        {
+            return o == null ? "" : o.ToString();
+        }
+        /// <summary>
+        /// 判断是否为空DBNull或者null或者""
+        /// </summary>
+        /// <param name="o"></param>
+        /// <returns></returns>
+        public static bool IsDBNullorNullorEmpty(object o)
+        {
+            if ((o is DBNull) || o == null || o.ToString() == "")
+            {
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 是否是Integer
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsInteger(string str)
+        {
+            int i;
+            return int.TryParse(str, out i);
+        }
+
+        public static bool IsNumber(string str)
+        {
+            double dbl;
+            return double.TryParse(str, out dbl);
+        }
+
+        /// <summary>
+        /// 判断字符串是否是正整数,可以是几十上百位的字符数
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsPositiveInteger(string str)
+        {
+            char[] arr = str.ToCharArray();
+            for (int i = 0; i < arr.Length; i++)
+            {
+                if (!IsInteger(arr[i].ToString()))
+                {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 是否是double
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsDouble(string str)
+        {
+            double dbl;
+            return double.TryParse(str, out dbl);
+        }
+        /// <summary>
+        /// 是否是single
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsSingle(string str)
+        {
+            Single flt;
+            return Single.TryParse(str, out flt);
+        }
+        /// <summary>
+        /// 是否为decimal
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsDecimal(string str)
+        {
+            decimal dec;
+            return Decimal.TryParse(str, out dec);
+        }
+
+        /// <summary>
+        /// 是否是ip地址
+        /// </summary>
+        /// <param name="ip"></param>
+        /// <returns></returns>
+        public static bool IsIP(string ip)
+        {
+            return Regex.IsMatch(ip, StringCommon.RegIp);
+
+        }
+
+        /// <summary>
+        /// 是否是手机号
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsCellPhone(string str)
+        {
+            Regex rphone = new Regex(StringCommon.RegCellphone);
+            return rphone.IsMatch(str);
+        }
+        /// <summary>
+        /// 是否是固话号
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsPhone(string str)
+        {
+            Regex rphone = new Regex(StringCommon.RegTelephone);
+            return rphone.IsMatch(str);
+        }
+
+        /// <summary>
+        /// 是否是邮箱地址
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsEmail(string str)
+        {
+            Regex remail = new Regex(StringCommon.RegEmail);
+            return remail.IsMatch(str);
+        }
+
+
+        /// <summary>
+        /// 是否是中国公民身份证号
+        /// </summary>
+        /// <param name="Id"></param>
+        /// <returns></returns>
+        public static bool IsIDCard(string Id)
+        {
+
+            if (Id.Length == 18)
+            {
+                return checkIDCard18(Id);
+
+            }
+            else if (Id.Length == 15)
+            {
+                return checkIDCard15(Id);
+            }
+            else
+            {
+                return false;
+            }
+        }
+        private static bool isIDCard18(string Id)
+        {
+            long n = 0;
+            if (long.TryParse(Id.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(Id.Replace('x', '0').Replace('X', '0'), out n) == false)
+            {
+                return false;//数字验证
+            }
+            string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
+            if (address.IndexOf(Id.Remove(2)) == -1)
+            {
+                return false;//省份验证
+            }
+            string birth = Id.Substring(6, 8).Insert(6, "-").Insert(4, "-");
+            DateTime time = new DateTime();
+            if (DateTime.TryParse(birth, out time) == false)
+            {
+                return false;//生日验证
+            }
+            string[] arrVarifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(',');
+            string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(',');
+            char[] Ai = Id.Remove(17).ToCharArray();
+            int sum = 0;
+            for (int i = 0; i < 17; i++)
+            {
+                sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString());
+            }
+            int y = -1;
+            Math.DivRem(sum, 11, out y);
+            if (arrVarifyCode[y] != Id.Substring(17, 1).ToLower())
+            {
+                return false;//校验码验证
+            }
+            return true;//符合GB11643-1999标准
+        }
+        /// <summary>    
+        /// 验证18位身份证号    
+        /// </summary>    
+        /// <param name="Id">身份证号</param>    
+        /// <returns>验证成功为True,否则为False</returns>   
+        private static bool checkIDCard18(string Id)
+        {
+
+            string birth = Id.Substring(6, 8).Insert(6, "-").Insert(4, "-");
+            DateTime time = new DateTime();
+            if (DateTime.TryParse(birth, out time) == false)
+            {
+                return false;//生日验证 
+            }
+
+            return true;//符合GB11643-1999标准 
+        }
+
+        /// <summary>    
+        /// 验证15位身份证号    
+        /// </summary>    
+        /// <param name="Id">身份证号</param>    
+        /// <returns>验证成功为True,否则为False</returns>  
+        private static bool checkIDCard15(string Id)
+        {
+
+            string birth = Id.Substring(6, 6).Insert(4, "-").Insert(2, "-");
+            DateTime time = new DateTime();
+            if (DateTime.TryParse(birth, out time) == false)
+            {
+                return false;//生日验证 
+            }
+            return true;//符合15位身份证标准 
+        }
+
+        public static bool CustomRegex(string inputStr, string express)
+        {
+            Regex regex = new Regex(express);
+            return regex.IsMatch(inputStr);
+        }
+
+
+
+        #endregion
+
+        #region 得到汉字首字母
+        /// <summary>
+        /// 根据区位得到首字母
+        /// </summary>
+        /// <param name="GBCode">区位</param>
+        /// <returns></returns>
+        private static String GetX(int GBCode)
+        {
+            if (GBCode >= 1601 && GBCode < 1637) return "A";
+            if (GBCode >= 1637 && GBCode < 1833) return "B";
+            if (GBCode >= 1833 && GBCode < 2078) return "C";
+            if (GBCode >= 2078 && GBCode < 2274) return "D";
+            if (GBCode >= 2274 && GBCode < 2302) return "E";
+            if (GBCode >= 2302 && GBCode < 2433) return "F";
+            if (GBCode >= 2433 && GBCode < 2594) return "G";
+            if (GBCode >= 2594 && GBCode < 2787) return "H";
+            if (GBCode >= 2787 && GBCode < 3106) return "J";
+            if (GBCode >= 3106 && GBCode < 3212) return "K";
+            if (GBCode >= 3212 && GBCode < 3472) return "L";
+            if (GBCode >= 3472 && GBCode < 3635) return "M";
+            if (GBCode >= 3635 && GBCode < 3722) return "N";
+            if (GBCode >= 3722 && GBCode < 3730) return "O";
+            if (GBCode >= 3730 && GBCode < 3858) return "P";
+            if (GBCode >= 3858 && GBCode < 4027) return "Q";
+            if (GBCode >= 4027 && GBCode < 4086) return "R";
+            if (GBCode >= 4086 && GBCode < 4390) return "S";
+            if (GBCode >= 4390 && GBCode < 4558) return "T";
+            if (GBCode >= 4558 && GBCode < 4684) return "W";
+            if (GBCode >= 4684 && GBCode < 4925) return "X";
+            if (GBCode >= 4925 && GBCode < 5249) return "Y";
+            if (GBCode >= 5249 && GBCode <= 5589) return "Z";
+            if (GBCode >= 5601 && GBCode <= 8794)
+            {
+                String CodeData = "cjwgnspgcenegypbtwxzdxykygtpjnmjqmbsgzscyjsyyfpggbzgydywjkgaljswkbjqhyjwpdzlsgmr"
+                 + "ybywwccgznkydgttngjeyekzydcjnmcylqlypyqbqrpzslwbdgkjfyxjwcltbncxjjjjcxdtqsqzycdxxhgckbphffss"
+                 + "pybgmxjbbyglbhlssmzmpjhsojnghdzcdklgjhsgqzhxqgkezzwymcscjnyetxadzpmdssmzjjqjyzcjjfwqjbdzbjgd"
+                 + "nzcbwhgxhqkmwfbpbqdtjjzkqhylcgxfptyjyyzpsjlfchmqshgmmxsxjpkdcmbbqbefsjwhwwgckpylqbgldlcctnma"
+                 + "eddksjngkcsgxlhzaybdbtsdkdylhgymylcxpycjndqjwxqxfyyfjlejbzrwccqhqcsbzkymgplbmcrqcflnymyqmsqt"
+                 + "rbcjthztqfrxchxmcjcjlxqgjmshzkbswxemdlckfsydsglycjjssjnqbjctyhbftdcyjdgwyghqfrxwckqkxebpdjpx"
+                 + "jqsrmebwgjlbjslyysmdxlclqkxlhtjrjjmbjhxhwywcbhtrxxglhjhfbmgykldyxzpplggpmtcbbajjzyljtyanjgbj"
+                 + "flqgdzyqcaxbkclecjsznslyzhlxlzcghbxzhznytdsbcjkdlzayffydlabbgqszkggldndnyskjshdlxxbcghxyggdj"
+                 + "mmzngmmccgwzszxsjbznmlzdthcqydbdllscddnlkjyhjsycjlkohqasdhnhcsgaehdaashtcplcpqybsdmpjlpcjaql"
+                 + "cdhjjasprchngjnlhlyyqyhwzpnccgwwmzffjqqqqxxaclbhkdjxdgmmydjxzllsygxgkjrywzwyclzmcsjzldbndcfc"
+                 + "xyhlschycjqppqagmnyxpfrkssbjlyxyjjglnscmhcwwmnzjjlhmhchsyppttxrycsxbyhcsmxjsxnbwgpxxtaybgajc"
+                 + "xlypdccwqocwkccsbnhcpdyznbcyytyckskybsqkkytqqxfcwchcwkelcqbsqyjqcclmthsywhmktlkjlychwheqjhtj"
+                 + "hppqpqscfymmcmgbmhglgsllysdllljpchmjhwljcyhzjxhdxjlhxrswlwzjcbxmhzqxsdzpmgfcsglsdymjshxpjxom"
+                 + "yqknmyblrthbcftpmgyxlchlhlzylxgsssscclsldclepbhshxyyfhbmgdfycnjqwlqhjjcywjztejjdhfblqxtqkwhd"
+                 + "chqxagtlxljxmsljhdzkzjecxjcjnmbbjcsfywkbjzghysdcpqyrsljpclpwxsdwejbjcbcnaytmgmbapclyqbclzxcb"
+                 + "nmsggfnzjjbzsfqyndxhpcqkzczwalsbccjxpozgwkybsgxfcfcdkhjbstlqfsgdslqwzkxtmhsbgzhjcrglyjbpmljs"
+                 + "xlcjqqhzmjczydjwbmjklddpmjegxyhylxhlqyqhkycwcjmyhxnatjhyccxzpcqlbzwwwtwbqcmlbmynjcccxbbsnzzl"
+                 + "jpljxyztzlgcldcklyrzzgqtgjhhgjljaxfgfjzslcfdqzlclgjdjcsnclljpjqdcclcjxmyzftsxgcgsbrzxjqqcczh"
+                 + "gyjdjqqlzxjyldlbcyamcstylbdjbyregklzdzhldszchznwczcllwjqjjjkdgjcolbbzppglghtgzcygezmycnqcycy"
+                 + "hbhgxkamtxyxnbskyzzgjzlqjdfcjxdygjqjjpmgwgjjjpkjsbgbmmcjssclpqpdxcdyykypcjddyygywchjrtgcnyql"
+                 + "dkljczzgzccjgdyksgpzmdlcphnjafyzdjcnmwescsglbtzcgmsdllyxqsxsbljsbbsgghfjlwpmzjnlyywdqshzxtyy"
+                 + "whmcyhywdbxbtlmswyyfsbjcbdxxlhjhfpsxzqhfzmqcztqcxzxrdkdjhnnyzqqfnqdmmgnydxmjgdhcdycbffallztd"
+                 + "ltfkmxqzdngeqdbdczjdxbzgsqqddjcmbkxffxmkdmcsychzcmljdjynhprsjmkmpcklgdbqtfzswtfgglyplljzhgjj"
+                 + "gypzltcsmcnbtjbhfkdhbyzgkpbbymtdlsxsbnpdkleycjnycdykzddhqgsdzsctarlltkzlgecllkjljjaqnbdggghf"
+                 + "jtzqjsecshalqfmmgjnlyjbbtmlycxdcjpldlpcqdhsycbzsckbzmsljflhrbjsnbrgjhxpdgdjybzgdlgcsezgxlblg"
+                 + "yxtwmabchecmwyjyzlljjshlgndjlslygkdzpzxjyyzlpcxszfgwyydlyhcljscmbjhblyjlycblydpdqysxktbytdkd"
+                 + "xjypcnrjmfdjgklccjbctbjddbblblcdqrppxjcglzcshltoljnmdddlngkaqakgjgyhheznmshrphqqjchgmfprxcjg"
+                 + "dychghlyrzqlcngjnzsqdkqjymszswlcfqjqxgbggxmdjwlmcrnfkkfsyyljbmqammmycctbshcptxxzzsmphfshmclm"
+                 + "ldjfyqxsdyjdjjzzhqpdszglssjbckbxyqzjsgpsxjzqznqtbdkwxjkhhgflbcsmdldgdzdblzkycqnncsybzbfglzzx"
+                 + "swmsccmqnjqsbdqsjtxxmbldxcclzshzcxrqjgjylxzfjphymzqqydfqjjlcznzjcdgzygcdxmzysctlkphtxhtlbjxj"
+                 + "lxscdqccbbqjfqzfsltjbtkqbsxjjljchczdbzjdczjccprnlqcgpfczlclcxzdmxmphgsgzgszzqjxlwtjpfsyaslcj"
+                 + "btckwcwmytcsjjljcqlwzmalbxyfbpnlschtgjwejjxxglljstgshjqlzfkcgnndszfdeqfhbsaqdgylbxmmygszldyd"
+                 + "jmjjrgbjgkgdhgkblgkbdmbylxwcxyttybkmrjjzxqjbhlmhmjjzmqasldcyxyqdlqcafywyxqhz";
+                String _gbcode = GBCode.ToString();
+                int pos = (Convert.ToInt16(_gbcode.Substring(0, 2)) - 56) * 94 + Convert.ToInt16(_gbcode.Substring(_gbcode.Length - 2, 2));
+                return CodeData.Substring(pos - 1, 1);
+            }
+            return " ";
+        }
+
+        /// <summary>
+        /// 得到单个汉字首字母大写
+        /// </summary>
+        /// <param name="OneIndexTxt"></param>
+        /// <returns></returns>
+        private static String GetOneIndex(String OneIndexTxt)
+        {
+            if (Convert.ToChar(OneIndexTxt) >= 0 && Convert.ToChar(OneIndexTxt) < 256)
+                return OneIndexTxt;
+            else
+            {
+                Encoding gb2312 = Encoding.GetEncoding("gb2312");
+                byte[] unicodeBytes = Encoding.Unicode.GetBytes(OneIndexTxt);
+                byte[] gb2312Bytes = Encoding.Convert(Encoding.Unicode, gb2312, unicodeBytes);
+                return GetX(Convert.ToInt32(
+                 String.Format("{0:D2}", Convert.ToInt16(gb2312Bytes[0]) - 160)
+                 + String.Format("{0:D2}", Convert.ToInt16(gb2312Bytes[1]) - 160)
+                 ));
+            }
+        }
+        /// <summary>
+        /// 得到汉字字符串的首字母大写
+        /// </summary>
+        /// <param name="IndexTxt"></param>
+        /// <returns></returns>
+        public static String GetChineseIndex(String IndexTxt)
+        {
+            String _Temp = null;
+            for (int i = 0; i < IndexTxt.Length; i++)
+                _Temp = _Temp + GetOneIndex(IndexTxt.Substring(i, 1));
+            return _Temp;
+        }
+
+        /// <summary>
+        /// 得到汉字的拼音字符串
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static string GetChineseSpell(string str)
+        {
+            int[] iA = new int[]
+     {
+      -20319 ,-20317 ,-20304 ,-20295 ,-20292 ,-20283 ,-20265 ,-20257 ,-20242 ,-20230
+      ,-20051 ,-20036 ,-20032 ,-20026 ,-20002 ,-19990 ,-19986 ,-19982 ,-19976 ,-19805
+      ,-19784 ,-19775 ,-19774 ,-19763 ,-19756 ,-19751 ,-19746 ,-19741 ,-19739 ,-19728
+      ,-19725 ,-19715 ,-19540 ,-19531 ,-19525 ,-19515 ,-19500 ,-19484 ,-19479 ,-19467
+      ,-19289 ,-19288 ,-19281 ,-19275 ,-19270 ,-19263 ,-19261 ,-19249 ,-19243 ,-19242
+      ,-19238 ,-19235 ,-19227 ,-19224 ,-19218 ,-19212 ,-19038 ,-19023 ,-19018 ,-19006
+      ,-19003 ,-18996 ,-18977 ,-18961 ,-18952 ,-18783 ,-18774 ,-18773 ,-18763 ,-18756
+      ,-18741 ,-18735 ,-18731 ,-18722 ,-18710 ,-18697 ,-18696 ,-18526 ,-18518 ,-18501
+      ,-18490 ,-18478 ,-18463 ,-18448 ,-18447 ,-18446 ,-18239 ,-18237 ,-18231 ,-18220
+      ,-18211 ,-18201 ,-18184 ,-18183 ,-18181 ,-18012 ,-17997 ,-17988 ,-17970 ,-17964
+      ,-17961 ,-17950 ,-17947 ,-17931 ,-17928 ,-17922 ,-17759 ,-17752 ,-17733 ,-17730
+      ,-17721 ,-17703 ,-17701 ,-17697 ,-17692 ,-17683 ,-17676 ,-17496 ,-17487 ,-17482
+      ,-17468 ,-17454 ,-17433 ,-17427 ,-17417 ,-17202 ,-17185 ,-16983 ,-16970 ,-16942
+      ,-16915 ,-16733 ,-16708 ,-16706 ,-16689 ,-16664 ,-16657 ,-16647 ,-16474 ,-16470
+      ,-16465 ,-16459 ,-16452 ,-16448 ,-16433 ,-16429 ,-16427 ,-16423 ,-16419 ,-16412
+      ,-16407 ,-16403 ,-16401 ,-16393 ,-16220 ,-16216 ,-16212 ,-16205 ,-16202 ,-16187
+      ,-16180 ,-16171 ,-16169 ,-16158 ,-16155 ,-15959 ,-15958 ,-15944 ,-15933 ,-15920
+      ,-15915 ,-15903 ,-15889 ,-15878 ,-15707 ,-15701 ,-15681 ,-15667 ,-15661 ,-15659
+      ,-15652 ,-15640 ,-15631 ,-15625 ,-15454 ,-15448 ,-15436 ,-15435 ,-15419 ,-15416
+      ,-15408 ,-15394 ,-15385 ,-15377 ,-15375 ,-15369 ,-15363 ,-15362 ,-15183 ,-15180
+      ,-15165 ,-15158 ,-15153 ,-15150 ,-15149 ,-15144 ,-15143 ,-15141 ,-15140 ,-15139
+      ,-15128 ,-15121 ,-15119 ,-15117 ,-15110 ,-15109 ,-14941 ,-14937 ,-14933 ,-14930
+      ,-14929 ,-14928 ,-14926 ,-14922 ,-14921 ,-14914 ,-14908 ,-14902 ,-14894 ,-14889
+      ,-14882 ,-14873 ,-14871 ,-14857 ,-14678 ,-14674 ,-14670 ,-14668 ,-14663 ,-14654
+      ,-14645 ,-14630 ,-14594 ,-14429 ,-14407 ,-14399 ,-14384 ,-14379 ,-14368 ,-14355
+      ,-14353 ,-14345 ,-14170 ,-14159 ,-14151 ,-14149 ,-14145 ,-14140 ,-14137 ,-14135
+      ,-14125 ,-14123 ,-14122 ,-14112 ,-14109 ,-14099 ,-14097 ,-14094 ,-14092 ,-14090
+      ,-14087 ,-14083 ,-13917 ,-13914 ,-13910 ,-13907 ,-13906 ,-13905 ,-13896 ,-13894
+      ,-13878 ,-13870 ,-13859 ,-13847 ,-13831 ,-13658 ,-13611 ,-13601 ,-13406 ,-13404
+      ,-13400 ,-13398 ,-13395 ,-13391 ,-13387 ,-13383 ,-13367 ,-13359 ,-13356 ,-13343
+      ,-13340 ,-13329 ,-13326 ,-13318 ,-13147 ,-13138 ,-13120 ,-13107 ,-13096 ,-13095
+      ,-13091 ,-13076 ,-13068 ,-13063 ,-13060 ,-12888 ,-12875 ,-12871 ,-12860 ,-12858
+      ,-12852 ,-12849 ,-12838 ,-12831 ,-12829 ,-12812 ,-12802 ,-12607 ,-12597 ,-12594
+      ,-12585 ,-12556 ,-12359 ,-12346 ,-12320 ,-12300 ,-12120 ,-12099 ,-12089 ,-12074
+      ,-12067 ,-12058 ,-12039 ,-11867 ,-11861 ,-11847 ,-11831 ,-11798 ,-11781 ,-11604
+      ,-11589 ,-11536 ,-11358 ,-11340 ,-11339 ,-11324 ,-11303 ,-11097 ,-11077 ,-11067
+      ,-11055 ,-11052 ,-11045 ,-11041 ,-11038 ,-11024 ,-11020 ,-11019 ,-11018 ,-11014
+      ,-10838 ,-10832 ,-10815 ,-10800 ,-10790 ,-10780 ,-10764 ,-10587 ,-10544 ,-10533
+      ,-10519 ,-10331 ,-10329 ,-10328 ,-10322 ,-10315 ,-10309 ,-10307 ,-10296 ,-10281
+      ,-10274 ,-10270 ,-10262 ,-10260 ,-10256 ,-10254
+     };
+            string[] sA = new string[]
+    {
+     "a","ai","an","ang","ao"
+     ,"ba","bai","ban","bang","bao","bei","ben","beng","bi","bian","biao","bie","bin"
+     ,"bing","bo","bu"
+     ,"ca","cai","can","cang","cao","ce","ceng","cha","chai","chan","chang","chao","che"
+     ,"chen","cheng","chi","chong","chou","chu","chuai","chuan","chuang","chui","chun"
+     ,"chuo","ci","cong","cou","cu","cuan","cui","cun","cuo"
+     ,"da","dai","dan","dang","dao","de","deng","di","dian","diao","die","ding","diu"
+     ,"dong","dou","du","duan","dui","dun","duo"
+     ,"e","en","er"
+     ,"fa","fan","fang","fei","fen","feng","fo","fou","fu"
+     ,"ga","gai","gan","gang","gao","ge","gei","gen","geng","gong","gou","gu","gua","guai"
+     ,"guan","guang","gui","gun","guo"
+     ,"ha","hai","han","hang","hao","he","hei","hen","heng","hong","hou","hu","hua","huai"
+     ,"huan","huang","hui","hun","huo"
+     ,"ji","jia","jian","jiang","jiao","jie","jin","jing","jiong","jiu","ju","juan","jue"
+     ,"jun"
+     ,"ka","kai","kan","kang","kao","ke","ken","keng","kong","kou","ku","kua","kuai","kuan"
+     ,"kuang","kui","kun","kuo"
+     ,"la","lai","lan","lang","lao","le","lei","leng","li","lia","lian","liang","liao","lie"
+     ,"lin","ling","liu","long","lou","lu","lv","luan","lue","lun","luo"
+     ,"ma","mai","man","mang","mao","me","mei","men","meng","mi","mian","miao","mie","min"
+     ,"ming","miu","mo","mou","mu"
+     ,"na","nai","nan","nang","nao","ne","nei","nen","neng","ni","nian","niang","niao","nie"
+     ,"nin","ning","niu","nong","nu","nv","nuan","nue","nuo"
+     ,"o","ou"
+     ,"pa","pai","pan","pang","pao","pei","pen","peng","pi","pian","piao","pie","pin","ping"
+     ,"po","pu"
+     ,"qi","qia","qian","qiang","qiao","qie","qin","qing","qiong","qiu","qu","quan","que"
+     ,"qun"
+     ,"ran","rang","rao","re","ren","reng","ri","rong","rou","ru","ruan","rui","run","ruo"
+     ,"sa","sai","san","sang","sao","se","sen","seng","sha","shai","shan","shang","shao","she"
+     ,"shen","sheng","shi","shou","shu","shua","shuai","shuan","shuang","shui","shun","shuo","si"
+     ,"song","sou","su","suan","sui","sun","suo"
+     ,"ta","tai","tan","tang","tao","te","teng","ti","tian","tiao","tie","ting","tong","tou","tu"
+     ,"tuan","tui","tun","tuo"
+     ,"wa","wai","wan","wang","wei","wen","weng","wo","wu"
+     ,"xi","xia","xian","xiang","xiao","xie","xin","xing","xiong","xiu","xu","xuan","xue","xun"
+     ,"ya","yan","yang","yao","ye","yi","yin","ying","yo","yong","you","yu","yuan","yue","yun"
+     ,"za","zai","zan","zang","zao","ze","zei","zen","zeng","zha","zhai","zhan","zhang","zhao"
+     ,"zhe","zhen","zheng","zhi","zhong","zhou","zhu","zhua","zhuai","zhuan","zhuang","zhui"
+     ,"zhun","zhuo","zi","zong","zou","zu","zuan","zui","zun","zuo"
+    };
+            byte[] B = new byte[2];
+            string s = "";
+            char[] c = str.ToCharArray();
+            for (int j = 0; j < c.Length; j++)
+            {
+                B = System.Text.Encoding.Default.GetBytes(c[j].ToString());
+                if ((int)(B[0]) <= 160 && (int)(B[0]) >= 0)
+                {
+                    s += c[j];
+                }
+                else
+                {
+                    for (int i = (iA.Length - 1); i >= 0; i--)
+                    {
+                        if (iA[i] <= (int)(B[0]) * 256 + (int)(B[1]) - 65536)
+                        {
+                            s += sA[i];
+                            break;
+                        }
+                    }
+                }
+            }
+            return s;
+        }
+
+        #endregion //得到汉字首字母
+    }
+}

+ 59 - 0
WebAPIBase.NetCore/WebAPIBase.NetCore.BusinessCore/BaseCore/UnitManager.cs

@@ -6,6 +6,7 @@ using System.Linq;
 using System.Text;
 using System.Data;
 using System.Linq.Expressions;
+using WebAPIBase.Utils;
 
 public class UnitManager : DbContext<Unit>
 {
@@ -577,4 +578,62 @@ public class UnitManager : DbContext<Unit>
         var list = Db.Queryable<Contract>().Where(lamda).OrderBy("ContractID DESC").ToList();
         return list;
     }
+
+    /// <summary>
+    /// 根据cbs费用项表中的费用编码,获取该费用各级费用编码的全编码
+    /// </summary>
+    /// <param name="costCode"></param>
+    /// <returns></returns>
+    public string GetCBSFullCode(string costCode)
+    {
+        var sql = $"SELECT dbo.GetCBSFullCode('{costCode}')";
+        var fullCode = Db.Ado.GetString(sql);
+        return fullCode;
+    }
+    /// <summary>
+    /// 根据费用代码获取该费用的全名称
+    /// </summary>
+    /// <param name="code"></param>
+    /// <returns></returns>
+    public string GetCostFullName(string code)
+    {
+        string text = "";
+        if (code.IsNullOrEmpty())
+        {
+            return text;
+        }
+
+        string cBSFullCode = GetCBSFullCode(code);
+        string[] array = cBSFullCode.Split('-');
+        int num = 0;
+
+        for (int i = num; i < array.Length; i++)
+        {
+            if (text != "")
+            {
+                text += "->";
+            }
+            text += GetCostName(array[i]);
+        }
+        return text;
+
+    }
+
+    /// <summary>
+    /// 根据费用代码获取费用名称
+    /// </summary>
+    /// <param name="code"></param>
+    /// <returns></returns>
+    public string GetCostName(string code)
+    {
+        string result = "";
+        if (code.IsNullOrEmpty())
+        {
+            return result;
+        }
+        var sql = $"SELECT CostName FROM dbo.cbs WHERE CostCode='{code}'";
+        result = Db.Ado.GetString(sql);
+        return result;
+
+    }
 }

+ 49 - 17
WebAPIBase.NetCore/WebAPIBase.NetCore.BusinessCore/BaseCore/ViseManager.cs

@@ -2,13 +2,45 @@
 using SqlSugar;
 using System;
 using System.Collections.Generic;
+using WebAPIBase.Utils;
+/// <summary>
+/// 待审签证管理类
+/// </summary>
 public class ViseManager : DbContext<Vise>
 {
- 
+
     //当前类已经继承了 DbContext增、删、查、改的方法
 
     //这里面写的代码不会给覆盖,如果要重新生成请删除 ViseManager.cs
+    /// <summary>
+    /// 获取待审签证列表
+    /// </summary>
+    /// <param name="projectCode"></param>
+    /// <param name="searchValue"></param>
+    /// <returns></returns>
+    public List<ViseDTO> GetVises(string projectCode, string searchValue = "")
+    {
+        var sql = $"SELECT v.ViseCode,v.ViseId,v.ViseName,v.ViseType,CONVERT(VARCHAR(10),v.ViseDate,120) ViseDate,v.State,dbo.GetUnitFullName(v.UnitCode) unitFullName, c.ContractName,v.ContractCode from Vise v INNER JOIN dbo.Contract c ON v.ContractCode=c.ContractCode where (dbo.GetUnitFullCode(v.UnitCode) like ('100000%')) and v.ProjectCode = '{projectCode}' and v.State ='0'  ";
+        if (searchValue.IsNotNullAndEmpty())
+        {
+            sql += $" and (v.ViseId='{searchValue}' or v.ViseName like '%{searchValue}%')";
+        }
+        sql += "  order by v.ViseCode desc";
+        var list = Db.Ado.SqlQuery<ViseDTO>(sql);
+        return list;
+    }
+    /// <summary>
+    /// 根据签证编码获取待审签证实例
+    /// </summary>
+    /// <param name="viseCode"></param>
+    /// <returns></returns>
+    public ViseDTO GetVise(string viseCode)
+    {
+        var sql = $"SELECT v.*,dbo.GetUnitFullName(v.UnitCode) unitFullName, c.ContractName from Vise v INNER JOIN dbo.Contract c ON v.ContractCode=c.ContractCode where  v.viseCode = '{viseCode}'  ";
 
+        var entity = Db.Ado.SqlQuerySingle<ViseDTO>(sql);
+        return entity;
+    }
 
     #region 教学方法
     /// <summary>
@@ -16,8 +48,8 @@ public class ViseManager : DbContext<Vise>
     /// </summary>
     public void Study()
     {
-	     
-	   /*********查询*********/
+
+        /*********查询*********/
 
         var data1 = ViseDb.GetById(1);//根据ID查询
         var data2 = ViseDb.GetList();//查询所有
@@ -30,7 +62,7 @@ public class ViseManager : DbContext<Vise>
 
         var data6 = ViseDb.GetPageList(it => 1 == 1, p, it => SqlFunc.GetRandom(), OrderByType.Asc);// 分页查询加排序
         Console.Write(p.PageCount);//返回总数
-     
+
         List<IConditionalModel> conModels = new List<IConditionalModel>(); //组装条件查询作为条件实现 分页查询加排序
         conModels.Add(new ConditionalModel() { FieldName = typeof(Vise).GetProperties()[0].Name, ConditionalType = ConditionalType.Equal, FieldValue = "1" });//id=1
         var data7 = ViseDb.GetPageList(conModels, p, it => SqlFunc.GetRandom(), OrderByType.Asc);
@@ -40,8 +72,8 @@ public class ViseManager : DbContext<Vise>
         //我要用事务
         var result = Db.Ado.UseTran(() =>
          {
-            //写事务代码
-        });
+             //写事务代码
+         });
         if (result.IsSuccess)
         {
             //事务成功
@@ -61,8 +93,8 @@ public class ViseManager : DbContext<Vise>
 
 
 
-		/*********更新*********/
-	    var updateData = new Vise() {  };//测试参数
+        /*********更新*********/
+        var updateData = new Vise() { };//测试参数
         var updateArray = new Vise[] { updateData };//测试参数
         ViseDb.Update(updateData);//根据实体更新
         ViseDb.UpdateRange(updateArray);//批量更新
@@ -71,16 +103,16 @@ public class ViseManager : DbContext<Vise>
 
 
 
-		/*********删除*********/
-	    var deldata = new Vise() {  };//测试参数
+        /*********删除*********/
+        var deldata = new Vise() { };//测试参数
         ViseDb.Delete(deldata);//根据实体删除
         ViseDb.DeleteById(1);//根据主键删除
-        ViseDb.DeleteById(new int[] { 1,2});//根据主键数组删除
-        ViseDb.Delete(it=>1==2);//根据条件删除
-        ViseDb.AsDeleteable().Where(it=>1==2).ExecuteCommand();//转成Deleteable实现复杂的操作
-    } 
+        ViseDb.DeleteById(new int[] { 1, 2 });//根据主键数组删除
+        ViseDb.Delete(it => 1 == 2);//根据条件删除
+        ViseDb.AsDeleteable().Where(it => 1 == 2).ExecuteCommand();//转成Deleteable实现复杂的操作
+    }
     #endregion
 
- 
- 
-}
+
+
+}

+ 311 - 0
WebAPIBase.NetCore/WebAPIBase.NetCore.Enties/DTO/ViseDTO.cs

@@ -0,0 +1,311 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+namespace Sugar.Enties
+{
+    public class ViseDTO
+    {
+        /// <summary>
+        /// 待审签证代码
+        /// </summary>
+        public string ViseCode { get; set; }
+        /// <summary>
+        /// 待审签证编号
+        /// </summary>
+        public string ViseId { get; set; }
+        /// <summary>
+        /// 待审签证名
+        /// </summary>
+        public string ViseName { get; set; }
+        /// <summary>
+        /// 签证类型
+        /// </summary>
+        public string ViseType { get; set; }
+
+        private string _viseDate;
+        /// <summary>
+        /// 签证日期
+        /// </summary>
+        public string ViseDate
+        {
+            get
+            {
+                return _viseDate?.Substring(0, 10);
+            }
+            set => _viseDate = value;
+        }
+
+        /// <summary>
+        /// 状态
+        /// </summary>
+        public string State { get; set; }
+        /// <summary>
+        /// 状态名
+        /// </summary>
+        public string StateName
+        {
+            get
+            {
+                int istate = Convert.ToInt32(State);
+                Type type = typeof(SimpleCheckState);
+                return type.GetEnumName(istate);
+            }
+        }
+
+
+        /// <summary>
+        /// 关联合同名
+        /// </summary>
+        public string ContractName { get; set; }
+        /// <summary>
+        /// 合同单号
+        /// </summary>
+        public string ContractCode { get; set; }
+        /// <summary>
+        /// 供应商名称
+        /// </summary>
+        public string SupplierName { get; set; }
+
+        /// <summary>
+        /// Desc:经办人代码
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string Person { get; set; }
+        /// <summary>
+        /// 经办人名
+        /// </summary>
+        public string PersonName { get; set; }
+
+        /// <summary>
+        /// Desc:所属部门代码
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string UnitCode { get; set; }
+
+        /// <summary>
+        /// 所属部门全称
+        /// </summary>
+        public string UnitFullName { get; set; }
+
+        private string _endDate;
+        /// <summary>
+        /// Desc:办理期限
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string EndDate
+        {
+            get
+            {
+                return _endDate?.Substring(0, 10);
+            }
+            set => _endDate = value;
+        }
+
+        /// <summary>
+        /// Desc:备注
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string Remark { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string Reason { get; set; }
+
+
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string ProjectCode { get; set; }
+
+
+
+        /// <summary>
+        /// Desc:审核人
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string CheckPerson { get; set; }
+
+        private string _CheckDate;
+        /// <summary>
+        /// Desc:审核日期
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string CheckDate
+        {
+            get
+            {
+                return _CheckDate?.Substring(0, 10);
+            }
+            set => _CheckDate = value;
+        }
+
+        /// <summary>
+        /// Desc:审核意见
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string CheckOpinion { get; set; }
+
+        /// <summary>
+        /// Desc:签证含税金额
+        /// Default:0
+        /// Nullable:True
+        /// </summary>           
+        public decimal? TotalCash { get; set; }
+
+        /// <summary>
+        /// Desc:币种
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string MoneyType { get; set; }
+
+        /// <summary>
+        /// Desc:汇率
+        /// Default:0
+        /// Nullable:True
+        /// </summary>           
+        public decimal? ExchangeRate { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:True
+        /// </summary>           
+        public decimal? TotalMoney { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string ViseIdEx { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string StateEx { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public decimal? TotalCheckCash { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public decimal? TotalCheckMoney { get; set; }
+
+        /// <summary>
+        /// Desc:暂估金额
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public decimal? EstimateCash { get; set; }
+
+        /// <summary>
+        /// Desc:报送金额
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public decimal? ReportCash { get; set; }
+
+        /// <summary>
+        /// Desc:申请单号
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public string RequisitionCode { get; set; }
+
+        /// <summary>
+        /// 申请单名
+        /// </summary>
+        public string RequisitionName { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:False
+        /// </summary>           
+        public decimal RateTotalCash { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:False
+        /// </summary>           
+        public decimal NoRateTotalCash { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:False
+        /// </summary>           
+        public decimal RateTotalMoney { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:False
+        /// </summary>           
+        public decimal NoRateTotalMoney { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:False
+        /// </summary>           
+        public decimal RateTotalCheckCash { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:False
+        /// </summary>           
+        public decimal NoRateTotalCheckCash { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:False
+        /// </summary>           
+        public decimal RateTotalCheckMoney { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:0
+        /// Nullable:False
+        /// </summary>           
+        public decimal NoRateTotalCheckMoney { get; set; }
+
+        /// <summary>
+        /// Desc:
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        public decimal? Rate { get; set; }
+
+    }
+}

+ 0 - 25
WebAPIBase.NetCore/WebAPIBase.NetCore.Enties/DbModels/MaterialInAndMaterialOutRelation.cs

@@ -1,25 +0,0 @@
-using System;
-using System.Linq;
-using System.Text;
-using SqlSugar;
-
-namespace Sugar.Enties
-{
-    /// <summary>
-    /// 入库单出库单关联表
-    /// </summary>
-    [SugarTable("MaterialInAndMaterialOutRelation")]
-    public partial class MaterialInAndMaterialOutRelation
-    {
-        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
-        public int Id { get; set; }
-        /// <summary>
-        /// 入库单编号
-        /// </summary>
-        public string MaterialInCode { get; set; }
-        /// <summary>
-        /// 领料单编号
-        /// </summary>
-        public string MaterialOutCode { get; set; }
-    }
-}

+ 0 - 34
WebAPIBase.NetCore/WebAPIBase.NetCore.Enties/ReturnResult.cs

@@ -1,34 +0,0 @@
-using Sugar.Enties;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Sugar.Enties
-{
-    /// <summary>
-    /// 返回结果对象
-    /// </summary>
-    public class ReturnResult<T>
-    {
-        /// <summary>
-        /// 登录是否成功
-        /// </summary>
-        public bool IsSuccess { get; set; }
-        /// <summary>
-        /// 若登录失败,返回的错误信息
-        /// </summary>
-        public string ErrorMsg { get; set; }
-
-        /// <summary>
-        /// 令牌
-        /// </summary>
-        public string token { get; set; }
-
-        /// <summary>
-        /// 返回查询接口的数据
-        /// </summary>
-        public T ReturnData { get; set; }
-    }
-}

+ 3 - 0
WebAPIBase.NetCore/WebAPIBase.NetCore.Enties/WebAPIBase.NetCore.Enties.csproj

@@ -6,4 +6,7 @@
   <ItemGroup>
     <PackageReference Include="sqlSugarCore" Version="5.0.0.18" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Utils\WebAPIBase.Utils.csproj" />
+  </ItemGroup>
 </Project>

+ 78 - 0
WebAPIBase.NetCore/WebAPIBase.NetCore/Controllers/ViseController.cs

@@ -0,0 +1,78 @@
+using NLog;
+using Org.BouncyCastle.Bcpg;
+using System;
+using WebAPIBase.API.Requests;
+using WebAPIBase.Service.Interface;
+using Newtonsoft.Json;
+using System.Net.Http;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using System.Net;
+using Sugar.Enties;
+using System.Text;
+using WebAPIBase.Utils;
+using Microsoft.Extensions.Configuration;
+using System.IO;
+using System.Collections.Specialized;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Caching.Memory;
+using Microsoft.AspNetCore.Authorization;
+using System.Drawing;
+using Microsoft.AspNetCore.Http;
+using System.Linq.Expressions;
+
+namespace WebAPIBase.API.Controllers
+{
+    /// <summary>
+    /// 待审签证
+    /// </summary>
+    [Produces("application/json;charset=UTF-8")]
+    [Route("api/Vise")]
+    public class ViseController : Controller
+    {
+        private static Logger logger = NLog.LogManager.GetCurrentClassLogger();
+
+        /// <summary>
+        /// 获取待审签证列表
+        /// </summary>
+        /// <param name="projectCode"></param>
+        /// <param name="searchValue"></param>
+        /// <returns></returns>
+        [HttpGet]
+        [Route("GetVises")]
+        public ActionResult GetVises(string projectCode, string searchValue = "")
+        {
+            var manager = new ViseManager();
+            var list = manager.GetVises(projectCode, searchValue);
+            return Json(list);
+        }
+
+        /// <summary>
+        /// 获取待审签证详情
+        /// </summary>
+        /// <param name="projectCode"></param>
+        /// <param name="searchValue"></param>
+        /// <returns></returns>
+        [HttpGet]
+        [Route("GetVise")]
+        public ActionResult GetVise(string viseCode)
+        {
+            var manager = new ViseManager();
+            var entity = manager.GetVise(viseCode);
+            var contract = new ContractManager().GetById(entity.ContractCode);
+            if (contract != null)
+            {
+                entity.SupplierName = new MaterialInManager().GetSupplierNameAndType(contract.SupplierCode, contract.SupplierTypeCode);
+            }
+            entity.PersonName = new SystemUserManager().GetById(entity.Person)?.UserName;
+            entity.RequisitionName = new RequisitionManager().GetById(entity.RequisitionCode)?.RequisitionName;
+
+            var data = new
+            {
+                mainEntity = entity
+            };
+            logger.Info($"【GetVise】data:{JsonConvert.SerializeObject(data)}");
+            return Json(data);
+        }
+    }
+}

+ 3 - 5
WebAPIBase.NetCore/WebAPIBase.NetCore/Startup.cs

@@ -104,11 +104,6 @@ namespace WebAPIBase.API
         public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
         {
 
-            //泛型方法添加中间件
-            app.UseMiddleware<CustomErrorMiddleware>();
-
-
-
             if (env.IsDevelopment())
             {
                 app.UseDeveloperExceptionPage();
@@ -120,6 +115,9 @@ namespace WebAPIBase.API
 
             app.UseAuthorization();
 
+            ///异常捕获的实现
+            app.UseCustomErrorMiddleware();
+
             app.UseCors();
 
             app.UseEndpoints(endpoints =>

+ 11 - 0
uni-app-front/common/api/viseApi.js

@@ -0,0 +1,11 @@
+import request from '@/common/axiosHelper.js'
+
+/* 获取待审签证列表 */
+ export function GetVises(projectCode, searchValue) {
+   return request({
+ 	url: '/Vise/GetVises',
+ 	method: 'get',
+ 	params:{projectCode:projectCode,searchValue:searchValue}
+   })
+ }
+ 

+ 9 - 0
uni-app-front/pages.json

@@ -194,6 +194,15 @@
             }
             
         }
+        ,{
+            "path" : "pages/template/GetVises/GetVises",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "待审签证列表",
+                "enablePullDownRefresh": false
+            }
+            
+        }
     ],
 	"globalStyle": {
 		"navigationBarTextStyle": "white",

+ 1 - 1
uni-app-front/pages/index/index.vue

@@ -224,7 +224,7 @@
 			},
 			toSign2() {
 				uni.navigateTo({
-					url: '/pages/template/requisitionlist/requisitionlist'
+					url: '/pages/template/GetVises/GetVises'
 				});
 			},
 			preventhuadong() {

+ 128 - 0
uni-app-front/pages/template/GetVises/GetVises.vue

@@ -0,0 +1,128 @@
+<template>
+	<view>
+		<view>
+			<uni-search-bar :radius="100" @confirm="search" @input="input" @cancel="cancel"></uni-search-bar>
+		</view>
+		<uni-list>
+			<uni-list-item v-for="(item, index) in listData" :key="index" @click="goDetail(item.materialInCode)" clickable >
+				<view slot="body" class="slot-box">
+					<view class="row">
+						<view class="column-left">编号:</view>
+						<view class="column-right">{{item.viseId}}</view>
+					</view>
+					<view class="row">
+						<view class="column-left">名称:</view>
+						<view class="column-right">{{item.viseName}}</view>
+					</view>
+					<view class="row">
+						<view class="column-left">日期:</view>
+						<view class="column-right">{{item.viseDate}}</view>
+					</view>
+					<view class="row">
+						<view class="column-left">所属部门:</view>
+						<view class="column-right">{{item.unitFullName}}</view>
+					</view>
+					<view class="row">
+						<view class="column-left">关联合同:</view>
+						<view class="column-right">{{item.contractName}}</view>
+					</view>
+					<view class="row">
+						<view class="column-left">状态:</view>
+						<view class="column-right">{{item.stateName}}</view>
+					</view>
+				</view>
+			</uni-list-item>
+		</uni-list>
+		<view style="bottom: 15px;right:10px;position: fixed;z-index: 50;">
+			<router-link to="/pages/template/MaterialInAdd/MaterialInAdd" style="text-decoration: none;" title="入库单添加">
+				<uni-icons type="plus-filled" size="80" color="#5678FE"></uni-icons>
+			</router-link>
+		</view>
+		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
+	</view>
+</template>
+
+<script>
+	import {
+		GetVises
+	} from "@/common/api/viseApi.js";
+	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
+	 
+	export default {
+		components: {
+			uniLoadMore
+		},
+		data() {
+			return {
+				listData: [],
+				searchvalue:'',
+				last_id: '',
+				reload: false,
+				status: 'more',
+
+				contentText: {
+					contentdown: '上拉加载更多',
+					contentrefresh: '加载中',
+					contentnomore: '没有更多'
+				}
+			};
+		},
+		onLoad() {
+			console.info("当前登录状态:" + this.$store.state.isLogin);
+			//console.info(this);
+			this.$util.persistLogin(this);
+		},
+		onPullDownRefresh() {
+			this.reload = true;
+			this.last_id = '';
+
+			this.getList();
+		},
+		onReachBottom() {
+			this.status = 'more';
+			this.getList();
+		},
+		created: function() {
+			this.getList();
+		},
+		methods: {
+
+			getList() {
+				let that = this;
+				let projectcode = that.$util.getState(that,'projectCode');				
+				let search = this.searchvalue;
+				
+				GetVises(projectcode, search).then((res) => {
+					console.info(res);
+					that.listData=[];
+					res.forEach(function(item, index, array) {
+						that.$set(that.listData, index, item);
+					});
+					console.info(that.listData);
+				});
+			},
+			goDetail: function(id) {
+				console.info('待审签证godetail',id);
+				uni.navigateTo({					
+					url: '/pages/template/GetVise/GetVise?id=' + id
+				});
+			},
+            search(res) { //回车搜索
+            	this.searchvalue = res.value; //赋值
+            	
+            	this.getList(); //调用搜索方法
+            },
+            input(res) {
+            	this.searchVal = res.value
+            },
+            cancel(res) {
+            	console.info('点击取消,输入值为:' + res.value);
+            	
+            }
+		}
+	};
+</script>
+
+<style scoped>
+	
+</style>