using Microsoft.AspNetCore.Mvc; using System; using System.ComponentModel; namespace Common.Helper.Response { public static class ResponseHelper { /// /// 首位: /// 3:warning /// 4:info(提示信息) /// 5:error; /// 6:后端校验,前端不报错 /// 倒数第二位: /// 0:代码校验出的错 /// 1:业务流程里面的错误 /// 4: notFind /// 5: 权限 /// public enum ErrorEnum { #region 3:warning //倒数第二位 0 //倒数第二位 1 /// /// 申请单已经发送到检验科,请联系检验科取消配血,并在his中删除医嘱及记账信息 /// [Description("申请单已经发送到检验科,请联系检验科取消配血,并在his中删除医嘱及记账信息")] HasBeenSent = 30011, /// /// 申请已发送或已作废,请勿重复操作 /// [Description("申请已发送或已作废,请勿重复操作")] RepeatSending = 30012, /// /// 条码作废- 改条码在检验科已经扫码上机,不能作废 /// [Description("该条码在检验科已经扫码上机,不能作废")] NotCancelBarcode = 30013, /// /// 检验科未发血 /// [Description("检验科未发血")] NotSend = 30014, /// /// 血袋已接收 /// [Description("血袋已接收")] BloodReceived = 30015, /// /// 操作时间不能超过当前时间 /// [Description("操作时间不能超过当前时间")] NurseTimeOut = 30016, /// /// 输注记录已反馈 /// [Description("输注记录已反馈")] InfusionFeedback = 3017, /// /// 输注记录已反馈 /// [Description("血袋配血科室不匹配")] DeptMismatch = 3018, [Description("自助申请单名称重复")] ApplicationNameRepeat = 30019, [Description("该用户码不属于此次采集场所")] UserCodeError = 300101, [Description("该申请未审核")] ApplicationNotAudit = 300102, [Description("Excel有误")] ExcelIsError = 300103, [Description("未付款")] Unpaid = 300104, [Description("该用户信息已经注册过")] UserInfoRepeat = 300105, [Description("该用户信息已经注册过")] UserBindRepeat = 300106, [Description("已超过最终上传时间")] UploadFileTimeOut = 300107, [Description("请登录")] NotLogin = 300108, [Description("团检申请不能停用")] GroupInspectionNotDelete = 300109, [Description("该申请已经停用")] ApplicationIsStop = 300120, //倒数第二位 4 /// /// 未找到数据 /// [Description("未找到数据")] NotFindData = 30041, /// /// 未找到输血申请单信息 /// [Description("未找到输血申请单信息")] NotFindBloodRequest = 30042, /// /// 未找到患者信息 /// [Description("未找到患者信息")] NotFindPatientInfo = 30043, /// /// 未找到样本信息 /// [Description("未找到样本信息")] NotFindSampleInfo = 30044, /// /// 未找到知情同意书信息 /// [Description("未找到知情同意书信息")] NotFindInformed = 30045, /// /// 未找到交叉配血信息 /// [Description("未找到交叉配血信息")] NotFindBloodMatch = 30046, /// /// 未找到血袋库存信息 /// [Description("未找到血袋库存信息")] NotFindBlood = 30047, /// /// 未找到输注记录数据 /// [Description("未找到输注记录")] NotFindInfusion = 30048, /// /// 未找到不良反应记录 /// [Description("未找到不良反应记录")] NotFindReaction = 30049, /// /// 未找到输注前巡视记录 /// [Description("未找到输注前巡视记录")] NotFindBeforeInspect = 30410, /// /// 未找到报告单 /// [Description("未找到报告单")] NotFindReport = 30411, //倒数第二位 5 权限 /// /// 输血申请未审核 /// [Description("输血申请未审核")] UnReviewBloodRequisition = 30051, /// /// 未进行医生审核 /// [Description("未进行医生审核")] UnReviewDoctor = 30052, /// /// 权限不足,医生无相关证书信息,如果确有证书请到his添加 /// [Description("权限不足,医生无相关证书信息,如果确有证书请到his添加")] InsufficientPermissions = 30053, /// /// 医生审核职称权限不足 /// [Description("权限不足,医生职称不符合审核要求")] InsufficientDoctorTitle = 30054, /// /// 护士审核权限不足 /// [Description("护士审核权限不足")] NurseInsufficient = 30055, #endregion #region 4:info /// /// 正在配血,请等待 /// [Description("正在配血,请等待")] Matching = 40011, #endregion #region 5:error /// /// Token错误 /// [Description("Token错误")] TokenError = 50001, [Description("参数错误")] ParamsError = 50002, [Description("登录失败,用户名或密码错误")] UserAndPwError = 50011, /// /// 医嘱业务流程错误-输血申请单发送 /// [Description("业务逻辑错误")] BusinessError = 50012, /// /// 血型未确认-创建知情同意书 /// [Description("患者血型未确认")] BloodAboRhError = 50013, /// /// 科室不匹配-首页获取在院患者列表 /// [Description("科室不匹配")] DeptMismatchError = 50014, #endregion #region 6:后端校验,前端不报错 [Description("登录失败,用户名或密码为空")] UserAndPwIsNull = 60001, #endregion } /// /// 获取枚举对应的Description /// /// /// public static string GetDescription(this Enum val) { var field = val.GetType().GetField(val.ToString()); if (field == null) return null; var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)); return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description; } /// /// 返回需单独处理错误的信息 /// /// /// public static ActionResult Fail(ErrorEnum enums) { var code = Convert.ToInt32(enums); var message = enums.GetDescription(); var result = new ResultModel(code, message, ""); return new OkObjectResult(result); } /// /// 返回需单独处理错误的信息,自定义message /// /// /// /// public static ActionResult Fail(ErrorEnum enums, string message) { var code = Convert.ToInt32(enums); var result = new ResultModel(code, message, ""); return new OkObjectResult(result); } /// /// /// /// /// /// public static ActionResult Fail(object data, ErrorEnum enums) { var result = new ResultModel(Convert.ToInt32(enums),enums.GetDescription(), data); return new OkObjectResult(result); } /// /// 成功(200,无返回) /// /// public static ActionResult Success() { var result = new ResultModel(200, "Success", ""); return new OkObjectResult(result); } /// /// 成功(200,返回数据) /// /// /// public static ActionResult Success(object data)//File(ms.ToArray(), "application/pdf"); { var result = new ResultModel(200, "Success", data); return new OkObjectResult(result); } /// /// 返回自定义错误 /// /// /// /// public static ActionResult CustomizeFail(string message, int code = 5) { code = code switch { 5 => 50001, 6 => 60001, 4 => 40001, 3 => 30001, _ => code }; return new OkObjectResult(new ResultModel(code, message, "")); } /// /// 失败(500) /// /// public static ActionResult ServerError() { var result = new ResultModel(500, "服务器内部错误,请联系系统管理员。", ""); return new OkObjectResult(result); } /// /// 失败(500) /// /// public static ActionResult Fail(Exception ex) { var result = new ResultModel(500, ex.Message, ""); return new OkObjectResult(result); } } public class ResultModel { public int Code { get; set; } public string Message { get; set; } public object Data { get; set; } public ResultModel() { } public ResultModel(int code, string message, object data) { Code = code; Message = message; Data = data; } } }