using Cksoft.Data;
using Cksoft.Data.Repository;
using DllEapDal.RA;
using DllEapEntity.Dtos;
using DllEapEntity.RA;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
namespace DllEapBll.RA
{
///
/// RA实验室设备上线维护
///
[Route("eap/api/[controller]/[action]")]
[ApiController]
[Authorize]
public class MachineRecipeController : ControllerBase
{
///
/// RA实验室机台数据查看
///
/// 序号
/// 状态
/// 设备ID
/// 机身码
/// 园区
/// IP地址
/// 厂商
/// 机台名称(先不管)
/// 机台类型
///
///
///
[HttpGet]
public LayuiModel Get(int id, string status, string fcode, string mcode, string macnum,string factory, string ipadress, string sname, string fname, string model,
int pageIndex = 1, int pageSize = 20)
{
using (IDatabase db = DbFactory.Base("RA"))
{
var m = new MachineInfo()
{
ID = id,
Factory = factory,
FCode = fcode,
MCode = mcode,
IPAdress = ipadress,
SName = sname,
FName = fname,
Model = model,
Status = status,
MacNum = macnum
};
var dal = new MacrecipeDal(db);
int total;
var data = dal.get(m, pageIndex, pageSize, out total);
return new LayuiModel
{
code = 1,
count = total,
data = data
};
}
}
[HttpPost]
public LayuiModel PostAdd([FromBody] MachineInfo m)
{
using (IDatabase db = DbFactory.Base("RA"))
{
var dal = new MacrecipeDal(db);
string data = "";
m.ModeCode = Request.Headers["usercode"];
m.ModeTime = DateTime.Now;
if (m.ID > 0)
{
data += dal.Update(m);
}
else
{
data += dal.Add(m);
}
return new LayuiModel
{
code = 1,
msg = data
};
}
}
[HttpPost]
public LayuiModel Delete([FromBody] MachineInfo m)
{
using (IDatabase db = DbFactory.Base("RA"))
{
var dal = new MacrecipeDal(db);
string Fcode = Request.Headers["usercode"];
string msg;
if (m.ID > 0)
{
msg = dal.delete(m.ID, Fcode);
}
else
{
msg = "没有收到有效的数据暂无法删除";
}
return new LayuiModel
{
code = 1,
msg = msg
};
}
}
[HttpPost]
public LayuiModel ReConnect([FromBody] MachineInfo m)
{
string msg = string.Empty;
if (m.ID > 0)
{
using (IDatabase db = DbFactory.Base("RA"))
{
var dal = new MacrecipeDal(db);
string Fcode = Request.Headers["usercode"];
if (dal.ReConnect(m.ID, Fcode))
{
msg = "重连成功";
}
}
}
else
{
msg = "参数错误";
}
return new LayuiModel
{
code = 1,
msg = msg
};
}
[HttpGet]
public IEnumerable> GetModel()
{
using (IDatabase db = DbFactory.Base("RA"))
{
var dal = new MacrecipeDal(db);
return dal.GetModel();
}
}
}
}