BusWorkorderDetailOperationService.cs 3.49 KB
using Hh.Mes.Common.Infrastructure;
using Hh.Mes.Common.log;
using Hh.Mes.Common.Request;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Hh.Mes.Service.Wo
{
    public class BusWorkorderDetailOperationService : RepositorySqlSugar<bus_workOrder_detail_rework>
    {
        public dynamic Load(PageReq pageReq, bus_workOrder_detail_rework entity)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var result = new Response<List<bus_workOrder_detail_rework>>();
                var expression = LinqWhere(entity);
                //先组合查询表达式
                var query = Context.Queryable<bus_workOrder_detail_rework>().Where(expression);
                //Exel为ture就不分页,因为导出的话是全部导出
                if (pageReq != null)
                {
                    int total = 0;
                    result.Result = query.OrderBy(x => x.createTime, OrderByType.Desc).ToOffsetPage(pageReq.page, pageReq.limit, ref total);
                    result.Count = total;
                }
                else
                {
                    result.Result = query.ToList();
                    result.Count = result.Result.Count;
                }
                return result;
            }, catchRetrunValue: "list");
        }

        public dynamic Ins(bus_workOrder_detail_rework entity)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var response = new Response();
                Context.Insertable(entity).ExecuteCommand();
                return response;
            });
        }

        public dynamic Upd(bus_workOrder_detail_rework entity)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var response = new Response();
                Context.Updateable(entity).ExecuteCommand();
                return response;
            });
        }

        public dynamic DelByIds(int[] ids)
        {
            return ExceptionsHelp.Instance.ExecuteT(() =>
            {
                var response = new Response();
                Context.Deleteable<bus_workOrder_detail_rework>(t => ids.Contains(t.id)).ExecuteCommand();
                return response;
            });
        }

        public Response ExportData(bus_workOrder_detail_rework entity)
        {
            return Load(null, entity);
        }

        public Expression<Func<bus_workOrder_detail_rework, bool>> LinqWhere(bus_workOrder_detail_rework model)
        {
            try
            {
                var exp = Expressionable.Create<bus_workOrder_detail_rework>();
                //数据过滤条件
                exp.AndIF(model.workOrderHeadKeys != Guid.Empty, x => x.workOrderHeadKeys == model.workOrderHeadKeys);
                exp.AndIF(!string.IsNullOrWhiteSpace(model.processCode), x => x.processCode.Contains(model.processCode));
                exp.AndIF(!string.IsNullOrWhiteSpace(model.lineCode), x => x.lineCode.Contains(model.lineCode));
                exp.AndIF(!string.IsNullOrWhiteSpace(model.productHeaderCode), x => x.productHeaderCode.Contains(model.productHeaderCode));
                return exp.ToExpression();//拼接表达式
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message}");
            }
        }
    }
}