From f06840f1a517245cf8cbd6da448416a54133284b Mon Sep 17 00:00:00 2001 From: wet Date: Sun, 15 May 2022 21:45:41 +0800 Subject: [PATCH] AMS --- ams/Djy.Common/DapperDBBase.cs | 10 +- ams/Djy.Common/Utilities/KeyDescription.cs | 24 +++ ams/Djy.Common/Utilities/TableData.cs | 52 +++++ ams/djy.IService/Ams/IAmsService.cs | 15 +- ams/djy.Model/Ams/AMS_Cntrno.cs | 17 +- ams/djy.Model/Ams/AMS_House.cs | 17 +- ams/djy.Model/Ams/AMS_Master.cs | 23 ++- ams/djy.Model/AmsDto/AMSDto.cs | 2 +- ams/djy.Model/AmsDto/AMSQuery.cs | 12 ++ ams/djy.Service/Ams/AmsService.cs | 184 ++++++++++++++---- .../Controllers/AMS/AmsController.cs | 45 ++++- 11 files changed, 329 insertions(+), 72 deletions(-) create mode 100644 ams/Djy.Common/Utilities/KeyDescription.cs create mode 100644 ams/Djy.Common/Utilities/TableData.cs create mode 100644 ams/djy.Model/AmsDto/AMSQuery.cs diff --git a/ams/Djy.Common/DapperDBBase.cs b/ams/Djy.Common/DapperDBBase.cs index 298f154..a68f853 100644 --- a/ams/Djy.Common/DapperDBBase.cs +++ b/ams/Djy.Common/DapperDBBase.cs @@ -276,7 +276,6 @@ namespace Common } /// /// 插入一组数据并且返回自动生成的主键的值 - /// Author GHB 2021-6-7 /// /// 要插入的数据 /// 自动生成的主键的值 @@ -291,7 +290,6 @@ namespace Common /// /// 批量插入数据并且返回插入数据的个数 - /// Author GHB 2021-6-7 /// /// 要插入的数据 /// 数量 @@ -516,6 +514,14 @@ namespace Common } } + public bool Update(T model) where T : class, new() + { + using (IDbConnection Conn = GetConn()) + { + return Conn.Update(model); + } + } + diff --git a/ams/Djy.Common/Utilities/KeyDescription.cs b/ams/Djy.Common/Utilities/KeyDescription.cs new file mode 100644 index 0000000..c7a91eb --- /dev/null +++ b/ams/Djy.Common/Utilities/KeyDescription.cs @@ -0,0 +1,24 @@ +namespace Common.Utilities +{ + public class KeyDescription + { + /// + /// 键值 + /// + public string Key { get; set; } + /// + /// 键的描述 + /// + public string Description { get; set; } + + /// + /// 前端是否显示 + /// + public bool Browsable { get; set; } + + /// + /// 字段类型 + /// + public string Type { get; set; } + } +} diff --git a/ams/Djy.Common/Utilities/TableData.cs b/ams/Djy.Common/Utilities/TableData.cs new file mode 100644 index 0000000..286ec4f --- /dev/null +++ b/ams/Djy.Common/Utilities/TableData.cs @@ -0,0 +1,52 @@ +// *********************************************************************** +// Assembly : FundationAdmin +// Author : yubaolee +// Created : 03-09-2016 +// +// Last Modified By : yubaolee +// Last Modified On : 03-09-2016 +// *********************************************************************** +// +// 版权所有(C) Microsoft 2015 +// +// layui datatable数据返回 +// *********************************************************************** + + +namespace Common.Utilities +{ + /// + /// table的返回数据 + /// + public class TableData + { + /// + /// 状态码 + /// + public int code { get; set; } + /// + /// 操作消息 + /// + public string msg { get; set; } + + /// + /// 总记录条数 + /// + public int count { get; set; } + + + + /// + /// 数据内容 + /// + public dynamic data { get; set; } + /// + /// + /// + public TableData() + { + code = 200; + msg = "加载成功"; + } + } +} \ No newline at end of file diff --git a/ams/djy.IService/Ams/IAmsService.cs b/ams/djy.IService/Ams/IAmsService.cs index 98b95c8..5382e6c 100644 --- a/ams/djy.IService/Ams/IAmsService.cs +++ b/ams/djy.IService/Ams/IAmsService.cs @@ -7,6 +7,7 @@ using djy.Model; using Common; using Common.Djy; using djy.Model.AmsDto; +using Common.Utilities; namespace djy.Paas.IService { @@ -16,13 +17,21 @@ namespace djy.Paas.IService public interface IAmsService:IsBase { /// - /// 新增 + /// 新增/编辑 /// /// /// void SaveInfo(AMSDto dto,string userid); - + /// + /// 查询 + /// + /// + /// + /// + TableData Load(AMSQuery req, string userid); + - List GetAll(); + + void Delete(string ids); } } diff --git a/ams/djy.Model/Ams/AMS_Cntrno.cs b/ams/djy.Model/Ams/AMS_Cntrno.cs index 78286c4..10e2843 100644 --- a/ams/djy.Model/Ams/AMS_Cntrno.cs +++ b/ams/djy.Model/Ams/AMS_Cntrno.cs @@ -1,18 +1,21 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Dapper.Contrib.Extensions; namespace djy.Model.Ams { [Table("AMS_Cntrno")] public class AMS_Cntrno { + + + + public AMS_Cntrno() + { + this.IsDel = "0"; + } /// /// 主键 /// + [ExplicitKey] public string GID { get; set; } /// @@ -93,6 +96,6 @@ namespace djy.Model.Ams public string LINKMAN { get; set; } - + public string IsDel { get; set; } } } diff --git a/ams/djy.Model/Ams/AMS_House.cs b/ams/djy.Model/Ams/AMS_House.cs index aaada91..8cc3c2e 100644 --- a/ams/djy.Model/Ams/AMS_House.cs +++ b/ams/djy.Model/Ams/AMS_House.cs @@ -1,18 +1,22 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Dapper.Contrib.Extensions; namespace djy.Model.Ams { [Table("AMS_House")] public class AMS_House { + + + + public AMS_House(){ + + this.IsDel = "0"; + + } /// /// 主键 /// + [ExplicitKey] public string GID { get; set; } /// @@ -84,5 +88,6 @@ namespace djy.Model.Ams /// 通知人电话 /// public string NOTIFYPARTYTEL { get; set; } + public string IsDel { get; set; } } } diff --git a/ams/djy.Model/Ams/AMS_Master.cs b/ams/djy.Model/Ams/AMS_Master.cs index a5b0562..38f184f 100644 --- a/ams/djy.Model/Ams/AMS_Master.cs +++ b/ams/djy.Model/Ams/AMS_Master.cs @@ -1,18 +1,21 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Dapper.Contrib.Extensions; +using System; + namespace djy.Model.Ams { [Table("AMS_Master")] public class AMS_Master { - /// - /// 主键 - /// + public AMS_Master() { + this.IsDel = "0"; + this.CreateTime = DateTime.Now; + } + /// + /// 主键 + /// + + [ExplicitKey] public string GID { get; set; } /// @@ -105,6 +108,6 @@ namespace djy.Model.Ams public DateTime? CreateTime { get; set; } public DateTime? LastUpdate { get; set; } - + public string IsDel { get; set; } } } diff --git a/ams/djy.Model/AmsDto/AMSDto.cs b/ams/djy.Model/AmsDto/AMSDto.cs index 39efc99..845262f 100644 --- a/ams/djy.Model/AmsDto/AMSDto.cs +++ b/ams/djy.Model/AmsDto/AMSDto.cs @@ -105,7 +105,7 @@ namespace djy.Model.AmsDto public DateTime? CreateTime { get; set; } public DateTime? LastUpdate { get; set; } - public List HouseDto { get; set; } + public List HouseDto { get; set; } = new List(); } public class AMS_HouseDto { diff --git a/ams/djy.Model/AmsDto/AMSQuery.cs b/ams/djy.Model/AmsDto/AMSQuery.cs new file mode 100644 index 0000000..ce7fd0f --- /dev/null +++ b/ams/djy.Model/AmsDto/AMSQuery.cs @@ -0,0 +1,12 @@ + +using Common.Entity; + +namespace djy.Model.AmsDto +{ + public class AMSQuery : PageEntity + { + public string MBLNO { get; set; } + + + } +} diff --git a/ams/djy.Service/Ams/AmsService.cs b/ams/djy.Service/Ams/AmsService.cs index 44fcb9a..03683c4 100644 --- a/ams/djy.Service/Ams/AmsService.cs +++ b/ams/djy.Service/Ams/AmsService.cs @@ -13,6 +13,9 @@ using Common.DjyService; using djy.Model.AmsDto; using Common.Extensions; using Common.DJYModel; +using System.Transactions; +using Dapper.Contrib.Extensions; +using Common.Utilities; namespace djy.Service.Ams { @@ -23,63 +26,172 @@ namespace djy.Service.Ams { DapperDBBase dapper = new DapperDBBase(); - - public List GetAll() + + + public TableData Load(AMSQuery req, string userid) { - throw new NotImplementedException(); + var result = new TableData(); + var user = DbBus.Get(DbList.djydb).Select().Where(w => w.GID == userid).ToOne(); + var dto = DbBus.Get(DbList.AMSCenter).Select().Where(x => x.IsDel == "0" || x.IsDel == null&&x.CompID==user.CompId).WhereIf(req.MBLNO != null, x => x.MBLNO == req.MBLNO); + result.count = dto.ToList().Count(); + var list= dto.Page(req.Page,req.Limit).ToList(); + if (list != null) { + foreach (var item in list) + { + var hodto = DbBus.Get(DbList.AMSCenter).Select().Where(x => x.IsDel == "0" || x.IsDel == null && x.PID == item.GID).ToList(); + item.HouseDto = hodto; + if (hodto!=null) { + foreach (var it in hodto) + { + var cnt = DbBus.Get(DbList.AMSCenter).Select().Where(x => x.IsDel == "0" || x.IsDel == null && x.HID == it.GID).ToList(); + it.CntrnoDto = cnt; + } + } + } + } + result.data = list; + return result; } - public async void SaveInfo(AMSDto dto,string userid) + public void Delete(string ids) { - if (dto.GID.IsNull()) + string[] id = ids.Split(','); + using (var transaction = new TransactionScope()) { - using (var transaction = dapper.BeginTransaction(dapper.GetConn())) + using (IDbConnection connection = dapper.GetConn()) { - try - { - var user = DbBus.Get(DbList.djydb).Select().Where(w => w.GID == userid).ToOne(); - AMS_Master master = dto.MapTo(); - master.CreateTime = DateTime.Now; - master.LastUpdate = DateTime.Now; - master.GID = Guid.NewGuid().ToString("N"); - master.UserID = user.GID; - master.UserName = user.SHOWNAME; - master.CompID = user.CompId; - master.CompName = user.COMNAME; - dapper.Insert(master); - foreach (var item in dto.HouseDto) + try { + foreach (string oid in id) { - AMS_House house = dto.MapTo(); - house.GID = Guid.NewGuid().ToString("N"); - house.PID = master.GID; - dapper.Insert(house); - foreach (var it in item.CntrnoDto) + if (oid != "") { - AMS_Cntrno cntrno = dto.MapTo(); - cntrno.GID = Guid.NewGuid().ToString("N"); - cntrno.PID = master.GID; - cntrno.HID = house.GID; - dapper.Insert(cntrno); + connection.Execute("update AMS_Cntrno set isdel ='1' where pid='" + oid + "'"); + connection.Execute("update AMS_House set isdel ='1' where pid='" + oid + "'"); + connection.Execute("update AMS_Master set isdel ='1' where gid='" + oid + "'"); } } - transaction.Rollback(); + transaction.Complete(); + connection.Dispose(); + connection.Close(); + } + catch (Exception ex) { + + connection.Dispose(); + connection.Close(); } - catch (Exception ex) + } + } + + + } + + + + public async void SaveInfo(AMSDto dto, string userid) + { + if (dto.GID.IsNull()) + { + var user = DbBus.Get(DbList.djydb).Select().Where(w => w.GID == userid).ToOne(); + using (var transaction = new TransactionScope()) + { + using (IDbConnection connection = dapper.GetConn()) { - transaction.Rollback(); + try + { + AMS_Master master = dto.MapTo(); + master.CreateTime = DateTime.Now; + master.LastUpdate = DateTime.Now; + master.GID = Guid.NewGuid().ToString("N"); + master.UserID = user.GID; + master.UserName = user.SHOWNAME; + master.CompID = user.CompId; + master.CompName = user.COMNAME; + connection.Insert(master); + if (dto.HouseDto != null && dto.HouseDto.Count() > 0) + { + foreach (var item in dto.HouseDto) + { + AMS_House house = dto.MapTo(); + house.GID = Guid.NewGuid().ToString("N"); + house.PID = master.GID; + connection.Insert(house); + if (item.CntrnoDto!=null&&item.CntrnoDto.Count()>0) { + foreach (var it in item.CntrnoDto) + { + AMS_Cntrno cntrno = dto.MapTo(); + cntrno.GID = Guid.NewGuid().ToString("N"); + cntrno.PID = master.GID; + cntrno.HID = house.GID; + connection.Insert(cntrno); + } + } + } + } + transaction.Complete(); + connection.Dispose(); + connection.Close(); + } + catch (Exception ex) + { + connection.Dispose(); + connection.Close(); + } } - } } - else { + else + { - + using (var transaction = new TransactionScope()) + { + using (IDbConnection connection = dapper.GetConn()) + { + try + { + + AMS_Master master = dto.MapTo(); + connection.Update(master); + connection.Execute("delete AMS_House where pid='"+ master.GID + "'"); + connection.Execute("delete AMS_Cntrno where pid='" + master.GID + "'"); + if (dto.HouseDto!=null&& dto.HouseDto.Count()>0) { + foreach (var item in dto.HouseDto) + { + AMS_House house = dto.MapTo(); + house.GID = Guid.NewGuid().ToString("N"); + house.PID = master.GID; + connection.Insert(house); + if (item.CntrnoDto!=null&&item.CntrnoDto.Count()>0) { + foreach (var it in item.CntrnoDto) + { + AMS_Cntrno cntrno = dto.MapTo(); + cntrno.GID = Guid.NewGuid().ToString("N"); + cntrno.PID = master.GID; + cntrno.HID = house.GID; + connection.Insert(cntrno); + } + } + } + } + transaction.Complete(); + connection.Dispose(); + connection.Close(); + } + catch (Exception ex) + { + connection.Dispose(); + connection.Close(); + + } + + + } + } } - + } } } diff --git a/ams/djy.WebApi/Controllers/AMS/AmsController.cs b/ams/djy.WebApi/Controllers/AMS/AmsController.cs index 033b24f..995024c 100644 --- a/ams/djy.WebApi/Controllers/AMS/AmsController.cs +++ b/ams/djy.WebApi/Controllers/AMS/AmsController.cs @@ -21,22 +21,53 @@ namespace djy_AmsApi.Controllers public Response AddOrUpdate(AMSDto Dto) { var result = new Response(); - //if (GetLoginId==null) { - // result.Code = 401; - // result.Message = "登录过期,请重新登录!"; - //} + if (GetLoginId == null) + { + result.Code = 401; + result.Message = "登录过期,请重新登录!"; + } if (Dto == null) { result.Code = 500; result.Message = "无效数据!"; } - ser.SaveInfo(Dto, "d85fd590-d9f6-4410-93a1-f6fac77b606e"); + ser.SaveInfo(Dto, GetLoginId.ToString()); return result; } - + [HttpGet("Load")] + public object Load([FromQuery] AMSQuery request) + { + if (GetLoginId == null) + { + var result = new Response(); + result.Code = 401; + result.Message = "登录过期,请重新登录!"; + return result; + } - + return ser.Load(request, GetLoginId.ToString()); } + + [HttpGet("Del")] + public Response Delete(string ids) + { + var result = new Response(); + try + { + ser.Delete(ids); + + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + + return result; + } + + } + }