using System; using SqlSugar; using Infrastructure.Attribute; using Infrastructure.Extensions; using ZR.Model; using ZR.Model.Dto; using ZR.Repository; using System.Linq; using ZR.Model.MES.mm; using ZR.Service.mes.mm.IService; namespace ZR.Service.Business { /// /// agv位置表Service业务层处理 /// [AppService(ServiceType = typeof(IMmAgvLocationService), ServiceLifetime = LifeTime.Transient)] public class MmAgvLocationService : BaseService, IMmAgvLocationService { /// /// 查询agv位置表列表 /// /// /// public PagedInfo GetList(MmAgvLocationQueryDto parm) { var predicate = Expressionable.Create() .AndIF(parm.areaCode!=0,it=>it.AreaCode==parm.areaCode); var response = Queryable() .Where(predicate.ToExpression()) .ToPage(parm); return response; } /// /// 获取详情 /// /// /// public MmAgvLocation GetInfo(int Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加agv位置表 /// /// /// public MmAgvLocation AddMmAgvLocation(MmAgvLocation model) { return Context.Insertable(model).ExecuteReturnEntity(); } /// /// 修改agv位置表 /// /// /// public int UpdateMmAgvLocation(MmAgvLocation model) { //var response = Update(w => w.Id == model.Id, it => new MmAgvLocation() //{ // AreaCode = model.AreaCode, // Area = model.Area, // Type = model.Type, // Coordinate = model.Coordinate, // Status = model.Status, // CreatedBy = model.CreatedBy, // CreatedTime = model.CreatedTime, // UpdatedBy = model.UpdatedBy, // UpdatedTime = model.UpdatedTime, //}); //return response; return Update(model, true); } /// /// 获取地域选择 /// /// public List<(int, string)> ListAreaOptions() { // 使用 LINQ 查询获取结果 var queryResult = Context.Queryable() .GroupBy(it => it.AreaCode) .Select(it => new { item1 = it.AreaCode, // 使用 Key 获取分组的键值 item2 = SqlFunc.AggregateMax(it.Area), // 聚合 Area 字段的最大值 }) .ToList(); // 将匿名对象转换为 List<(int, string)> List<(int, string)> lists = queryResult .Select(item => ((int)item.item1, item.item2)) .ToList(); return lists; } /// /// 更改状态 /// /// /// /// public int Updatestatus(int index, int status) { return Context.Updateable().Where(it=>it.Id==index).SetColumns(it=>it.Status==status).ExecuteCommand(); } } }