155 lines
4.6 KiB
C#
155 lines
4.6 KiB
C#
using Common.DbExtends;
|
|
using Common.DbExtends.Extends;
|
|
using Common.Models;
|
|
using Common.Models.Enums;
|
|
using Common.Models.JsonModels;
|
|
using Common.Models.UnqTables;
|
|
using Common.Utils;
|
|
using Model.JsonModels;
|
|
using Newtonsoft.Json;
|
|
using Server.MyClass.Views;
|
|
using Server.Utils;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
|
|
namespace Server.Controllers.FunctionSetting
|
|
{
|
|
public class BaseController : DefaultController
|
|
{
|
|
/// <summary>
|
|
/// 获取基础配置模板
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult GetConfig()
|
|
{
|
|
var Id = GetInt("Id", true);
|
|
|
|
var baseConfig = Db.GetBaseConfigById(Id);
|
|
if (baseConfig == null) baseConfig = new BaseConfig();
|
|
|
|
return PutData(baseConfig);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增基础配置模板
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult AddBaseConfig()
|
|
{
|
|
string Name = GetString("Name", true);
|
|
string Cfg = GetString("Cfg", true);
|
|
var config = Db.Queryable<ConfigData>().Where(f => f.Name == Name && f.Type == Common.Models.Enums.ConfigType.基础).First();
|
|
|
|
if (config != null)
|
|
return PutData("新增失败,此模板名称已存在");
|
|
config = new ConfigData();
|
|
config.Type = ConfigType.基础;
|
|
config.JsonContent = Cfg;
|
|
config.Name = Name;
|
|
Db.Save(config);
|
|
|
|
return PutSuccess;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑基础设置模板
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult UpdBaseConfig()
|
|
{
|
|
var Id = GetInt("Id", true);
|
|
string Cfg = GetString("Cfg", true);
|
|
var config = Db.GetConfigData(Id);
|
|
|
|
if (config == null)
|
|
return PutData("编辑失败,没有此模板");
|
|
|
|
if (config.Type != Common.Models.Enums.ConfigType.基础)
|
|
{
|
|
return PutData("编辑失败,此模板类型不匹配");
|
|
}
|
|
|
|
config.JsonContent = Cfg;
|
|
Db.Save(config);
|
|
|
|
//通知应用了配置的机器人
|
|
var robots = Db.Queryable<Robot>().Where(f => f.ConfigBaseId == config.Id).ToList();
|
|
foreach (var robot in robots)
|
|
Client.SendClientMsg(robot.Id, DeviceMessageType.基础配置修改, new { ConfigId = config.Id });
|
|
|
|
return PutSuccess;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取基础设置模板的名称
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult GetBaseNames()
|
|
{
|
|
var PageIndex = GetInt("PageIndex", true);
|
|
var PageSize = GetInt("PageSize", true);
|
|
if (PageSize > 100) PageSize = 100;
|
|
|
|
var keyword = GetString("keyword");
|
|
var totalNumber = 0;
|
|
|
|
var exp = Expressionable.Create<ConfigData>();
|
|
|
|
if (!string.IsNullOrEmpty(keyword))
|
|
{
|
|
exp.And(f => f.Name.Contains(keyword) && f.Type == Common.Models.Enums.ConfigType.基础);
|
|
}
|
|
|
|
else
|
|
{
|
|
exp.And(f => f.Type == Common.Models.Enums.ConfigType.基础);
|
|
}
|
|
|
|
var DataList = Db.Queryable<ConfigData>()
|
|
.Where(exp.ToExpression())
|
|
.Select(M => new BaseConfigShow
|
|
{
|
|
BaseConfigId = M.Id,
|
|
BaseConfigName = M.Name,
|
|
})
|
|
.ToPageList(PageIndex, PageSize, ref totalNumber);
|
|
|
|
var res = new PageResult<BaseConfigShow>(DataList, totalNumber, PageSize, PageIndex);
|
|
return PutData(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除基础设置模板
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost, ErrorFilter]
|
|
public WebResult DelBaseConfig()
|
|
{
|
|
var Id = GetInt("Id", true);
|
|
var config = Db.Queryable<ConfigData>().Single(f => f.Id == Id);
|
|
|
|
if (config != null)
|
|
{
|
|
var res = Db.Delete(config);
|
|
|
|
if (res > 0) return PutSuccess;
|
|
}
|
|
|
|
return PutData("删除失败,此模板不存在");
|
|
}
|
|
}
|
|
}
|