using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WMS.Core.APPBLL; using WMS.Info; using WMS.Util; namespace WMS.Core.ServiceCore { public class WcsRouteService { /// /// 获取分页数据 /// /// public IEnumerable GetPageList(Pagination pagination, string queryJson) { SqlSugarClient client = null; try { client = WCSDbCore.GetDbCtx(); int count = 0; var queryParam = queryJson.ToJObject(); var db = client.Queryable(); if (!queryParam["keyword"].IsEmpty()) { string kw = queryParam["keyword"].ToString(); db.Where(ord => ord.Devicecode.Contains(kw)); } //if (!queryParam["NAME"].IsEmpty()) //{ // string name = queryParam["NAME"].ToString(); // db.Where(o => o.Name.Contains(name)); //} //if (!queryParam["IP"].IsEmpty()) //{ // string ip = queryParam["IP"].ToString(); // db.Where(o => o.Ip.Contains(ip)); //} //if (!queryParam["PORT"].IsEmpty()) //{ // string port = queryParam["PORT"].ToString(); // db.Where(o => o.Port.ToString().Contains(port)); //} if (pagination.sord.ToUpper() != "ASC") { pagination.sidx = pagination.sidx + " DESC"; } var list = db.OrderBy(pagination.sidx).Select(@"*").ToPageList(pagination.page, pagination.rows, ref count); pagination.records = count; return list; } catch (Exception ex) { throw ex; } finally { client.Dispose(); } } /// /// 获取实体数据 /// 主键 /// /// public WcsRouteEntity GetEntity(string keyValue) { try { return WCSDbCore.GetDbCtx().Queryable().Where(it => it.Id == keyValue.ToInt()).First(); } catch (Exception ex) { throw ex; } } /// /// 删除实体数据 /// 主键 /// /// public void DeleteEntity(string keyValue) { try { //SysDbCore.GetDbCtx().Deleteable().Where(it => it.F_NO == keyValue).ExecuteCommand(); WCSDbCore.GetDbCtx().Deleteable().Where(it => it.Id == keyValue.ToInt()).ExecuteCommand(); } catch (Exception ex) { throw ex; } } /// /// 保存实体数据(新增、修改) /// 主键 /// /// public void SaveEntity(LoginUserInfo loginUserInfo, string keyValue, WcsRouteEntity entity) { if (entity == null) { throw SysExCore.ThrowFailException("输入数据为空。"); } if (string.IsNullOrWhiteSpace(entity.Devicecode)) { throw SysExCore.ThrowFailException("编码为空。"); } if (entity.Devicecode == entity.Nextcode) { throw SysExCore.ThrowFailException("设备编号和下一个设备编号不能一样"); } entity.Updatetime = DateTime.Now; entity.Updateuser = loginUserInfo.UserNo; if (string.IsNullOrEmpty(keyValue)) { using (var ctx = WCSDbCore.GetDbCtx()) { var item = ctx.Queryable().First(o => o.Devicecode == entity.Devicecode && o.Nextcode==entity.Nextcode); if (item != null) { throw SysExCore.ThrowFailException("添加路由时,设备编号和下一个设备编号不能重复。"); } entity.Updatetime = DateTime.Now; entity.Updateuser = loginUserInfo.UserNo; entity.Enabled = true; ctx.Insertable(entity).ExecuteCommand(); } } else { WCSDbCore.GetDbCtx().Updateable(entity).Where(it => it.Id == keyValue.ToInt()).ExecuteCommand(); } } } }