yz_server/Server/Controllers/MemberManagement/FansController.cs

163 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Common.DbExtends.Extends;
using Common.Models.Enums;
using Common.Models.SubTables;
using Common.Models.UnqTables;
using Common.Utils;
using Server.MyClass.Views;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
namespace Server.Controllers.MemberManagement
{
/// <summary>
/// 进粉记录
/// </summary>
public class FansController : DefaultController
{
/// <summary>
/// 获取机器人信息
/// </summary>
/// <returns></returns>
[HttpPost, ErrorFilter]
public WebResult GetRobotInfo()
{
var Keyword = GetString("Keyword");
var exp = Expressionable.Create<Robot>();
if (!string.IsNullOrEmpty(Keyword))
{
exp.And(f => f.Nickname.Contains(Keyword));
}
var robotInfos = Db.Queryable<Robot>().Where(exp.ToExpression())
.Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }).Take(20).ToList();
return PutData(robotInfos);
}
/// <summary>
/// 查询进粉记录
/// </summary>
/// <returns></returns>
[HttpPost, ErrorFilter]
public WebResult GetFansRecord()
{
var RobotId = GetInt("RobotId");
var MinTime = GetTime("MinTime");
var MaxTime = GetTime("MaxTime");
var PageIndex = GetInt("PageIndex", true);
var PageSize = GetInt("PageSize", true);
if (PageSize > 100) PageSize = 100;
var tNumber = 0;
var exp = Expressionable.Create<FansRecord>();
if (RobotId > 0)
exp.And(f => f.RobotId == RobotId);
if (MinTime != DateTime.MinValue)
exp.And(f => f.CreateTime > MinTime);
if (MaxTime != DateTime.MinValue)
exp.And(f => f.CreateTime < MaxTime);
var list = Db.Queryable<FansRecord>()
.SplitTable(MinTime, MaxTime)
.LeftJoin<Robot>((f, b) => f.RobotId == b.Id)
.Where(exp.ToExpression())
.Select((f, b) => new FansRecordShow
{
Id = f.Id,
ApplyRemark = f.ApplyRemark,
CreateTime = f.CreateTime,
Nickname = f.Nickname,
Username = f.Username,
SourceNickname = f.SourceNickname,
SourceUsername = f.SourceUsername,
Type = f.Type,
RobotId = f.RobotId,
RobotName = b.Nickname,
Gender = f.Gender,
Operation = f.Operation,
}).ToPageList(PageIndex, PageSize, ref tNumber);
var res = new PageResult<FansRecordShow>(list, tNumber, PageSize, PageIndex);
return PutData(res);
}
/// <summary>
/// 设置进粉状态
/// </summary>
/// <returns></returns>
[HttpPost, ErrorFilter]
public WebResult AddMoniData()
{
FansRecord f = new FansRecord()
{
ApplyRemark = "aa",
CreateTime = DateTime.Now,
Gender = SexType.,
Nickname = GetString("Nickname", true),
Operation = OperationStatus.,
RobotId = 1,
SourceNickname = "",
SourceUsername = "",
Type = UserType.,
Username = Guid.NewGuid().ToString("N"),
};
f.Id = Util.CreateID(f.CreateTime);//自己写的一个算法ID可以根据时间计算出表名
Db.Insertable(f).SplitTable().ExecuteCommand();
return PutData(f);
}
/// <summary>
/// 设置进粉状态
/// </summary>
/// <returns></returns>
[HttpPost, ErrorFilter]
public WebResult SetRecordStatus()
{
//需要读long否则越界
var Id = GetLong("Id", true);
//获取表名
var TableName = Db.GetTableNameById<FansRecord>(Id);
var record = Db.Queryable<FansRecord>().Where(f => f.Id == Id).SplitTable(tab => tab.InTableNames(TableName)).First();
if (record == null) return PutData("操作失败,当前数据不存在!");
//var MinTime = GetTime("MinTime", true);
//var MaxTime = GetTime("MaxTime", true);
//var record = Db.Queryable<FansRecord>().SplitTable(MinTime, MaxTime).Single(f => f.Id == Id);
//if (record == null)
//{
// return PutError;
//}
var op = GetEnum<OperationStatus>("State", true);
record.Operation = op;
Db.Updateable(record).SplitTable(tab => tab.InTableNames(TableName)).ExecuteCommand();
//if (op == record.Operation)
//{
// return PutError;
//}
////TODO 向机器人发送同步好友状态消息
//record.Operation = op;
////TODO 同步分表数据库
////Db.Updateable(record).SplitTable(MinTime, MaxTime).ExecuteCommand();
return PutSuccess;
}
}
}