master
wet 3 years ago
parent a90b36c3f1
commit f06840f1a5

@ -276,7 +276,6 @@ namespace Common
} }
/// <summary> /// <summary>
/// 插入一组数据并且返回自动生成的主键的值 /// 插入一组数据并且返回自动生成的主键的值
/// Author GHB 2021-6-7
/// </summary> /// </summary>
/// <param name="entity">要插入的数据</param> /// <param name="entity">要插入的数据</param>
/// <returns>自动生成的主键的值</returns> /// <returns>自动生成的主键的值</returns>
@ -291,7 +290,6 @@ namespace Common
/// <summary> /// <summary>
/// 批量插入数据并且返回插入数据的个数 /// 批量插入数据并且返回插入数据的个数
/// Author GHB 2021-6-7
/// </summary> /// </summary>
/// <param name="entitys">要插入的数据</param> /// <param name="entitys">要插入的数据</param>
/// <returns>数量</returns> /// <returns>数量</returns>
@ -516,6 +514,14 @@ namespace Common
} }
} }
public bool Update<T>(T model) where T : class, new()
{
using (IDbConnection Conn = GetConn())
{
return Conn.Update<T>(model);
}
}

@ -0,0 +1,24 @@
namespace Common.Utilities
{
public class KeyDescription
{
/// <summary>
/// 键值
/// </summary>
public string Key { get; set; }
/// <summary>
/// 键的描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 前端是否显示
/// </summary>
public bool Browsable { get; set; }
/// <summary>
/// 字段类型
/// </summary>
public string Type { get; set; }
}
}

@ -0,0 +1,52 @@
// ***********************************************************************
// Assembly : FundationAdmin
// Author : yubaolee
// Created : 03-09-2016
//
// Last Modified By : yubaolee
// Last Modified On : 03-09-2016
// ***********************************************************************
// <copyright file="TableData.cs" company="Microsoft">
// 版权所有(C) Microsoft 2015
// </copyright>
// <summary>layui datatable数据返回</summary>
// ***********************************************************************
namespace Common.Utilities
{
/// <summary>
/// table的返回数据
/// </summary>
public class TableData
{
/// <summary>
/// 状态码
/// </summary>
public int code { get; set; }
/// <summary>
/// 操作消息
/// </summary>
public string msg { get; set; }
/// <summary>
/// 总记录条数
/// </summary>
public int count { get; set; }
/// <summary>
/// 数据内容
/// </summary>
public dynamic data { get; set; }
/// <summary>
///
/// </summary>
public TableData()
{
code = 200;
msg = "加载成功";
}
}
}

@ -7,6 +7,7 @@ using djy.Model;
using Common; using Common;
using Common.Djy; using Common.Djy;
using djy.Model.AmsDto; using djy.Model.AmsDto;
using Common.Utilities;
namespace djy.Paas.IService namespace djy.Paas.IService
{ {
@ -16,13 +17,21 @@ namespace djy.Paas.IService
public interface IAmsService:IsBase public interface IAmsService:IsBase
{ {
/// <summary> /// <summary>
/// 新增 /// 新增/编辑
/// </summary> /// </summary>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <param name="userid"></param> /// <param name="userid"></param>
void SaveInfo(AMSDto dto,string userid); void SaveInfo(AMSDto dto,string userid);
/// <summary>
/// 查询
/// </summary>
/// <param name="req"></param>
/// <param name="userid"></param>
/// <returns></returns>
TableData Load(AMSQuery req, string userid);
List<AMSDto> GetAll(); void Delete(string ids);
} }
} }

@ -1,18 +1,21 @@
using System; using Dapper.Contrib.Extensions;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Model.Ams namespace djy.Model.Ams
{ {
[Table("AMS_Cntrno")] [Table("AMS_Cntrno")]
public class AMS_Cntrno public class AMS_Cntrno
{ {
public AMS_Cntrno()
{
this.IsDel = "0";
}
/// <summary> /// <summary>
/// 主键 /// 主键
/// </summary> /// </summary>
[ExplicitKey]
public string GID { get; set; } public string GID { get; set; }
/// <summary> /// <summary>
@ -93,6 +96,6 @@ namespace djy.Model.Ams
public string LINKMAN { get; set; } public string LINKMAN { get; set; }
public string IsDel { get; set; }
} }
} }

@ -1,18 +1,22 @@
using System; using Dapper.Contrib.Extensions;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Model.Ams namespace djy.Model.Ams
{ {
[Table("AMS_House")] [Table("AMS_House")]
public class AMS_House public class AMS_House
{ {
public AMS_House(){
this.IsDel = "0";
}
/// <summary> /// <summary>
/// 主键 /// 主键
/// </summary> /// </summary>
[ExplicitKey]
public string GID { get; set; } public string GID { get; set; }
/// <summary> /// <summary>
@ -84,5 +88,6 @@ namespace djy.Model.Ams
/// 通知人电话 /// 通知人电话
/// </summary> /// </summary>
public string NOTIFYPARTYTEL { get; set; } public string NOTIFYPARTYTEL { get; set; }
public string IsDel { get; set; }
} }
} }

@ -1,18 +1,21 @@
using System; using Dapper.Contrib.Extensions;
using System.Collections.Generic; using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Model.Ams namespace djy.Model.Ams
{ {
[Table("AMS_Master")] [Table("AMS_Master")]
public class AMS_Master public class AMS_Master
{ {
public AMS_Master() {
this.IsDel = "0";
this.CreateTime = DateTime.Now;
}
/// <summary> /// <summary>
/// 主键 /// 主键
/// </summary> /// </summary>
[ExplicitKey]
public string GID { get; set; } public string GID { get; set; }
/// <summary> /// <summary>
@ -105,6 +108,6 @@ namespace djy.Model.Ams
public DateTime? CreateTime { get; set; } public DateTime? CreateTime { get; set; }
public DateTime? LastUpdate { get; set; } public DateTime? LastUpdate { get; set; }
public string IsDel { get; set; }
} }
} }

@ -105,7 +105,7 @@ namespace djy.Model.AmsDto
public DateTime? CreateTime { get; set; } public DateTime? CreateTime { get; set; }
public DateTime? LastUpdate { get; set; } public DateTime? LastUpdate { get; set; }
public List<AMS_HouseDto> HouseDto { get; set; } public List<AMS_HouseDto> HouseDto { get; set; } = new List<AMS_HouseDto>();
} }
public class AMS_HouseDto { public class AMS_HouseDto {

@ -0,0 +1,12 @@

using Common.Entity;
namespace djy.Model.AmsDto
{
public class AMSQuery : PageEntity
{
public string MBLNO { get; set; }
}
}

@ -13,6 +13,9 @@ using Common.DjyService;
using djy.Model.AmsDto; using djy.Model.AmsDto;
using Common.Extensions; using Common.Extensions;
using Common.DJYModel; using Common.DJYModel;
using System.Transactions;
using Dapper.Contrib.Extensions;
using Common.Utilities;
namespace djy.Service.Ams namespace djy.Service.Ams
{ {
@ -24,21 +27,78 @@ namespace djy.Service.Ams
DapperDBBase dapper = new DapperDBBase(); DapperDBBase dapper = new DapperDBBase();
public List<AMSDto> GetAll()
public TableData Load(AMSQuery req, string userid)
{
var result = new TableData();
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
var dto = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().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<AMSDto>();
if (list != null) {
foreach (var item in list)
{
var hodto = DbBus.Get(DbList.AMSCenter).Select<AMS_House>().Where(x => x.IsDel == "0" || x.IsDel == null && x.PID == item.GID).ToList<AMS_HouseDto>();
item.HouseDto = hodto;
if (hodto!=null) {
foreach (var it in hodto)
{ {
throw new NotImplementedException(); var cnt = DbBus.Get(DbList.AMSCenter).Select<AMS_Cntrno>().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)
{ {
string[] id = ids.Split(',');
using (var transaction = new TransactionScope())
{
using (IDbConnection connection = dapper.GetConn())
{
try {
foreach (string oid in id)
{
if (oid != "")
{
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.Complete();
connection.Dispose();
connection.Close();
}
catch (Exception ex) {
connection.Dispose();
connection.Close();
}
}
}
}
public async void SaveInfo(AMSDto dto, string userid)
{
if (dto.GID.IsNull()) if (dto.GID.IsNull())
{ {
using (var transaction = dapper.BeginTransaction(dapper.GetConn())) var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
using (var transaction = new TransactionScope())
{
using (IDbConnection connection = dapper.GetConn())
{ {
try try
{ {
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
AMS_Master master = dto.MapTo<AMS_Master>(); AMS_Master master = dto.MapTo<AMS_Master>();
master.CreateTime = DateTime.Now; master.CreateTime = DateTime.Now;
master.LastUpdate = DateTime.Now; master.LastUpdate = DateTime.Now;
@ -47,35 +107,87 @@ namespace djy.Service.Ams
master.UserName = user.SHOWNAME; master.UserName = user.SHOWNAME;
master.CompID = user.CompId; master.CompID = user.CompId;
master.CompName = user.COMNAME; master.CompName = user.COMNAME;
dapper.Insert<AMS_Master>(master); connection.Insert<AMS_Master>(master);
if (dto.HouseDto != null && dto.HouseDto.Count() > 0)
{
foreach (var item in dto.HouseDto) foreach (var item in dto.HouseDto)
{ {
AMS_House house = dto.MapTo<AMS_House>(); AMS_House house = dto.MapTo<AMS_House>();
house.GID = Guid.NewGuid().ToString("N"); house.GID = Guid.NewGuid().ToString("N");
house.PID = master.GID; house.PID = master.GID;
dapper.Insert<AMS_House>(house); connection.Insert<AMS_House>(house);
if (item.CntrnoDto!=null&&item.CntrnoDto.Count()>0) {
foreach (var it in item.CntrnoDto) foreach (var it in item.CntrnoDto)
{ {
AMS_Cntrno cntrno = dto.MapTo<AMS_Cntrno>(); AMS_Cntrno cntrno = dto.MapTo<AMS_Cntrno>();
cntrno.GID = Guid.NewGuid().ToString("N"); cntrno.GID = Guid.NewGuid().ToString("N");
cntrno.PID = master.GID; cntrno.PID = master.GID;
cntrno.HID = house.GID; cntrno.HID = house.GID;
dapper.Insert<AMS_Cntrno>(cntrno); connection.Insert<AMS_Cntrno>(cntrno);
}
} }
} }
transaction.Rollback(); }
transaction.Complete();
connection.Dispose();
connection.Close();
} }
catch (Exception ex) catch (Exception ex)
{ {
transaction.Rollback(); connection.Dispose();
connection.Close();
}
}
}
} }
else
{
using (var transaction = new TransactionScope())
{
using (IDbConnection connection = dapper.GetConn())
{
try
{
AMS_Master master = dto.MapTo<AMS_Master>();
connection.Update<AMS_Master>(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<AMS_House>();
house.GID = Guid.NewGuid().ToString("N");
house.PID = master.GID;
connection.Insert<AMS_House>(house);
if (item.CntrnoDto!=null&&item.CntrnoDto.Count()>0) {
foreach (var it in item.CntrnoDto)
{
AMS_Cntrno cntrno = dto.MapTo<AMS_Cntrno>();
cntrno.GID = Guid.NewGuid().ToString("N");
cntrno.PID = master.GID;
cntrno.HID = house.GID;
connection.Insert<AMS_Cntrno>(cntrno);
}
}
} }
} }
else { transaction.Complete();
connection.Dispose();
connection.Close();
}
catch (Exception ex)
{
connection.Dispose();
connection.Close();
}
}
}
} }

@ -21,20 +21,51 @@ namespace djy_AmsApi.Controllers
public Response AddOrUpdate(AMSDto Dto) public Response AddOrUpdate(AMSDto Dto)
{ {
var result = new Response(); var result = new Response();
//if (GetLoginId==null) { if (GetLoginId == null)
// result.Code = 401; {
// result.Message = "登录过期,请重新登录!"; result.Code = 401;
//} result.Message = "登录过期,请重新登录!";
}
if (Dto == null) if (Dto == null)
{ {
result.Code = 500; result.Code = 500;
result.Message = "无效数据!"; result.Message = "无效数据!";
} }
ser.SaveInfo(Dto, "d85fd590-d9f6-4410-93a1-f6fac77b606e"); ser.SaveInfo(Dto, GetLoginId.ToString());
return result; 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;
}
} }

Loading…
Cancel
Save