using System; using SqlSugar; using Infrastructure.Attribute; using Infrastructure.Extensions; using DOAN.Model; using DOAN.Repository; using System.Linq; using DOAN.Model.MES.dev; using DOAN.Model.MES.dev.Dto; using DOAN.Service.MES.dev.IService; using static System.Runtime.InteropServices.JavaScript.JSType; namespace DOAN.Service.MES.dev { /// /// 巡检计划Service业务层处理 /// [AppService(ServiceType = typeof(IDeviceRouteInspectionPlanService), ServiceLifetime = LifeTime.Transient)] public class DeviceRouteInspectionPlanService : BaseService, IDeviceRouteInspectionPlanService { /// /// 查询巡检计划列表 /// /// /// public PagedInfo GetList(DeviceRouteInspectionPlanQueryDto parm) { var predicate = Expressionable.Create(); predicate.AndIF(!string.IsNullOrEmpty(parm.Name), it => it.Name.Contains(parm.Name)) .AndIF(parm.LifeCycleStart != null, it => it.LifeCycleStart >= parm.LifeCycleStart) .AndIF(parm.LifeCycleEnd != null, it => it.LifeCycleEnd <= parm.LifeCycleEnd) .AndIF(parm.ExcuteCycleType > 0, it => it.ExcuteCycleType == parm.ExcuteCycleType) .AndIF(parm.InnerType>-1, it => it.InnerType == parm.InnerType); var response = Queryable() .Where(predicate.ToExpression()) .ToPage(parm); return response; } /// /// 获取详情 /// /// /// public DeviceRouteInspectionPlan GetInfo(string Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加巡检计划 /// /// /// public DeviceRouteInspectionPlan AddDeviceRouteInspectionPlan(DeviceRouteInspectionPlan model) { model.Id = SnowFlakeSingle.Instance.NextId().ToString(); switch (model.ExcuteCycleType) { case 1: model.WeekList = ""; model.MonthDayList = ""; break; case 2: model.DayNum = null; model.MonthDayList = ""; break; case 3: model.DayNum = null; model.WeekList = ""; break; } return Context.Insertable(model).ExecuteReturnEntity(); } /// /// 修改巡检计划 /// /// /// public int UpdateDeviceRouteInspectionPlan(DeviceRouteInspectionPlan model) { switch (model.ExcuteCycleType) { // 每日 case 1: model.WeekList = ""; model.MonthDayList = ""; break; //每周 case 2: model.DayNum = null; model.MonthDayList = ""; break; //每月 case 3: model.WeekList = ""; model.DayNum = null; break; } var response = Update(w => w.Id == model.Id, it => new DeviceRouteInspectionPlan() { Name = model.Name, Status = model.Status, InnerType = model.InnerType, LifeCycleStart = model.LifeCycleStart, LifeCycleEnd = model.LifeCycleEnd, ExcuteCycleType = model.ExcuteCycleType, DayNum = model.DayNum, WeekList = model.WeekList, MonthDayList = model.MonthDayList, Remark = model.Remark, UpdatedBy = model.UpdatedBy, UpdatedTime = model.UpdatedTime, }); return response; // return Update(model, true); } } }