123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using Cksoft.Unity;
- using Cksoft.Unity.Log4NetConfig;
- using DllEapDal;
- using DllEapEntity;
- using DllUfpDal;
- using DllUfpEntity;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- namespace DllEapBll.Controllers
- {
- /// <summary>
- /// 邮件设置
- /// </summary>
- [Authorize]
- [ApiController]
- [Route("eap/api/[controller]/[action]")]
- public class MailSettingsController : ControllerBase
- {
- private readonly string conn = "eap";
- /// <summary>
- /// 获取邮件设置项列表
- /// </summary>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="filter"></param>
- /// <param name="sort"></param>
- /// <param name="order"></param>
- /// <returns></returns>
- [HttpGet]
- public LayuiModel<MailSettings> GetMailSettingsList(int pageIndex = 1, int pageSize = 10, string filter = "", string sort = "FCode", string order = "ASC")
- {
- if (string.IsNullOrEmpty(sort) || sort.ToString().ToLower() == "null")
- sort = "FCode";
- if (order == "descend")
- order = "desc";
- else
- {
- order = "asc";
- }
- IEnumerable<MailSettings> list = null;
- filter = filter ?? " ";
- using (IDatabase db = DbFactory.Base("eapslave"))
- {
- var dal = new MailSettingsDal(db);
- int start = (pageIndex - 1) * pageSize + 1;
- string errorinfo = string.Empty;
- list = dal.GetMailSettingsList(start, pageSize, filter, sort, order, ref errorinfo);
- var count = dal.GetMailSettingsCount(filter);
- var responseData = new LayuiModel<MailSettings>()
- {
- code = 0,
- count = count,
- data = list,
- msg = ""
- };
- return responseData;
- }
- }
- /// <summary>
- /// 设置详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- public MailSettings GetMailSettingsDetail(int id)
- {
- using (IDatabase db = DbFactory.Base("eapslave"))
- {
- var dal = new MailSettingsDal(db);
- MailSettings staff = dal.GetMailSettings(id);
- return staff;
- }
- }
- /// <summary>
- /// 新增/修改设置
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- [HttpPost]
- public string AddOrUpdateMailSettings([FromBody] MailSettings model)
- {
- var id = model.ID;
- string errorinfo = string.Empty;
- var usercode = Request.Headers["usercode"];
- IDatabase db = DbFactory.Base(conn);
- try
- {
- db.BeginTrans();
- var dal = new MailSettingsDal(db);
- if (id == 0)
- {
- model.RecCode = usercode;
- model.ModCode = usercode;
- model.MailBody = string.IsNullOrEmpty(model.MailBody) ? "" : model.MailBody;
- model.Remark = string.IsNullOrEmpty(model.Remark) ? "" : model.Remark;
- var resInsert = dal.InsertMailSettings(model, ref errorinfo);
- if (resInsert > 0)
- {
- db.Commit();
- LogHelper<MailSettings>.LogFatal("新增MailSettings-->" + Json.ToJson(model), "用户操作", model.RecCode);
- return JsonConvert.SerializeObject(new { id = resInsert, msg = string.Empty });
- }
- db.Rollback();
- return JsonConvert.SerializeObject(new { id = "0", msg = errorinfo });
- }
- var oldModel = dal.GetMailSettings(id);
- if (oldModel == null)
- return JsonConvert.SerializeObject(new { id = "0", msg = "此邮件类别不存在" });
- model.ModCode = usercode;
- model.ModTime = DateTime.Now;
- var resUpdate = dal.UpdateMailSettings(model, usercode, ref errorinfo);
- if (resUpdate > 0)
- {
- db.Commit();
- LogHelper<MailSettings>.LogFatal("修改MailSettings-->原始数据:" + Json.ToJson(oldModel) + " 新数据:" + Json.ToJson(model), "用户操作", model.RecCode);
- return JsonConvert.SerializeObject(new { id = resUpdate });
- }
- db.Rollback();
- return JsonConvert.SerializeObject(new { id = "0", msg = errorinfo }); ;
- }
- catch (Exception e)
- {
- db.Rollback();
- return JsonConvert.SerializeObject(new { id = "0", msg = e.Message });
- }
- finally
- {
- if (db != null)
- db.Close();
- }
- }
- /// <summary>
- /// 删除邮件设置
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<EapResponse> Delete([FromBody] int id)
- {
- using (IDatabase db = DbFactory.Base("eap"))
- {
- db.BeginTrans();
- var dal = new MailSettingsDal(db);
- var res = await dal.DeleteMailSetting(id);
- db.Commit();
- return res;
- }
- }
- /// <summary>
- /// 获取邮件接收人
- /// </summary>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="filter"></param>
- /// <param name="sort"></param>
- /// <param name="order"></param>
- /// <returns></returns>
- [HttpGet]
- public LayuiModel<MailReceiver> GetMailReceiverList(int pageIndex = 1, int pageSize = 10, string filter = "", string sort = "id", string order = "ASC")
- {
- if (string.IsNullOrEmpty(sort) || sort.ToString().ToLower() == "null")
- sort = "id";
- if (order == "descend")
- order = "desc";
- else
- {
- order = "asc";
- }
- IEnumerable<MailReceiver> list = null;
- filter += " and IsValid=1";
- filter = filter ?? " ";
- using (IDatabase db = DbFactory.Base("eapslave"))
- {
- var dal = new MailSettingsDal(db);
- int start = (pageIndex - 1) * pageSize + 1;
- string errorinfo = string.Empty;
- list = dal.GetMailReceiverList(start, pageSize, filter, sort, order, ref errorinfo);
- foreach (var model in list)
- {
- switch (model.SendType)
- {
- case 1:
- model.SendTypeName = "收件人";
- break;
- case 2:
- model.SendTypeName = "抄送人";
- break;
- }
- }
- var count = dal.GetMailReceiverCount(filter);
- var responseData = new LayuiModel<MailReceiver>()
- {
- code = 0,
- count = count,
- data = list,
- msg = ""
- };
- return responseData;
- }
- }
- /// <summary>
- /// 接收人详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- public MailReceiver GetMailReceiverDetail(int id)
- {
- using (IDatabase db = DbFactory.Base("eapslave"))
- {
- var dal = new MailSettingsDal(db);
- MailReceiver staff = dal.GetMailReceiver(id);
- return staff;
- }
- }
- /// <summary>
- /// 新增/修改接收人
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- [HttpPost]
- public string AddOrUpdateMailReceiver([FromBody] MailReceiver model)
- {
- var id = model.ID;
- string errorinfo = string.Empty;
- var usercode = Request.Headers["usercode"];
- IDatabase db = DbFactory.Base(conn);
- try
- {
- db.BeginTrans();
- var dal = new MailSettingsDal(db);
- if (id == 0)
- {
- model.RecCode = usercode;
- model.ModCode = usercode;
- model.IsValid = 1;
- var resInsert = dal.InsertMailReceiver(model, ref errorinfo);
- if (resInsert > 0)
- {
- db.Commit();
- LogHelper<MailReceiver>.LogFatal("新增MailReceiver-->" + Json.ToJson(model), "用户操作", model.RecCode);
- return JsonConvert.SerializeObject(new { id = resInsert, msg = string.Empty });
- }
- db.Rollback();
- return JsonConvert.SerializeObject(new { id = "0", msg = errorinfo });
- }
- var oldModel = dal.GetMailReceiver(id);
- if (oldModel == null)
- return JsonConvert.SerializeObject(new { id = "0", msg = "此收件人不存在" });
- model.ModCode = usercode;
- model.ModTime = DateTime.Now;
- model.IsValid = 1;
- int resUpdate = dal.UpdateMailReceiver(model, usercode, ref errorinfo);
- if (resUpdate > 0)
- {
- db.Commit();
- LogHelper<MailReceiver>.LogFatal("修改MailReceiver-->原始值:" + Json.ToJson(oldModel) + " 新值:" + Json.ToJson(model), "用户操作", model.RecCode);
- return JsonConvert.SerializeObject(new { id = resUpdate });
- }
- db.Rollback();
- return JsonConvert.SerializeObject(new { id = "0", msg = errorinfo }); ;
- }
- catch (Exception e)
- {
- db.Rollback();
- return JsonConvert.SerializeObject(new { id = "0", msg = e.Message });
- }
- finally
- {
- if (db != null)
- db.Close();
- }
- }
- /// <summary>
- /// 删除接收人
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet]
- public string DeleteMailReceiver(int id)
- {
- string errorinfo = string.Empty;
- var usercode = Request.Headers["usercode"];
- IDatabase db = DbFactory.Base(conn);
- try
- {
- db.BeginTrans();
- var dal = new MailSettingsDal(db);
- var model = dal.GetMailReceiver(id);
- var res = dal.DeleteMailReceiver(id, usercode, ref errorinfo);
- if (res > 0)
- {
- db.Commit();
- LogHelper<MailReceiver>.LogFatal("删除MailReceiver-->MailReceiver:" + Json.ToJson(model), "用户操作", usercode);
- return JsonConvert.SerializeObject(new { id = res, msg = string.Empty });
- }
- db.Rollback();
- return JsonConvert.SerializeObject(new { id = "0", msg = errorinfo });
- }
- catch (Exception e)
- {
- db.Rollback();
- return JsonConvert.SerializeObject(new { id = "0", msg = e.Message });
- }
- finally
- {
- if (db != null)
- db.Close();
- }
- }
- /// <summary>
- /// 发送邮件
- /// </summary>
- /// <param name="code"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- [HttpGet]
- [AllowAnonymous]
- public string SendMail(string code, int type = 1)
- {
- if (code == AppConfigurtaionServices.Configuration["DisConnNoticeCode"])
- {
- var result = MailNotice.DisconnectionNotice(type).Result;
- return JsonConvert.SerializeObject(new { code = string.IsNullOrEmpty(result) ? 1 : 0, msg = string.IsNullOrEmpty(result) ? "发送成功" : result });
- }
- else
- {
- return JsonConvert.SerializeObject(new { code = 0, msg = "此邮件暂未开发" });
- }
- }
- /// <summary>
- /// 发送AA抛料率预警
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [AllowAnonymous]
- public async Task<string> SendAAMaterial()
- {
- var result = await MailNotice.AAMaterialUploadErrorNotice();
- return JsonConvert.SerializeObject(new { code = string.IsNullOrEmpty(result) ? 1 : 0, msg = string.IsNullOrEmpty(result) ? "发送成功" : result });
- }
- /// <summary>
- /// 发送断线、IP不一致、小程序未开启预警邮件
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [AllowAnonymous]
- public string SendMailNew()
- {
- var result = MailNotice.IPDifferentAndDiconnectionNotice().Result;
- return JsonConvert.SerializeObject(new { code = string.IsNullOrEmpty(result) ? 1 : 0, msg = string.IsNullOrEmpty(result) ? "发送成功" : result });
- }
- }
- }
|