Пример #1
0
        /// <summary>
        /// 获取T_MM_PurchaseApplyMain主表数据数据
        /// </summary>
        /// <param name="requestObject">Get请求参数</param>
        /// <param name="currentUser">当前操作用户</param>
        /// <returns>返回响应结果对象,包括响应代码,查询操作结果</returns>
        public async Task <ResponseObject <List <TMMPurchaseApplyMainQueryModel> > > GetMainListAsync(RequestGet requestObject, CurrentUser currentUser)
        {
            try
            {
                List <TMMPurchaseApplyMainQueryModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber = -1;                        //总记录数
                var            query       = _db.Instance.Queryable <TMMPurchaseApplyMainDbModel, TMMProductionOrderMainDbModel,
                                                                     TSMUserAccountDbModel, TSMUserAccountDbModel>(
                    (t, t0, t1, t2) => new object[]
                {
                    JoinType.Left, t.SourceId == t0.ID,
                    JoinType.Left, t.OperatorId == t1.ID,
                    JoinType.Left, t.AuditId == t1.ID
                }).Where((t, t0, t1, t2) => t.DeleteFlag == false);
                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var otherQuery = requestObject.QueryConditions.Where(p => p.Column.ToLower() == "sourceno").ToList();

                    if (otherQuery.Count() > 0)
                    {
                        var con = SqlSugarUtil.GetConditionalModels(otherQuery);
                        foreach (ConditionalModel item in con)
                        {
                            item.FieldName = "ProductionNo";
                            item.FieldName = $"t0.{item.FieldName}";
                        }
                        query.Where(con);
                    }

                    var thisQuery = requestObject.QueryConditions.Where(p => p.Column.ToLower() != "sourceno").ToList();
                    if (thisQuery.Count() > 0)
                    {
                        var conditionals = SqlSugarUtil.GetConditionalModels(thisQuery);
                        foreach (ConditionalModel item in conditionals)
                        {
                            item.FieldName = $"t.{item.FieldName}";
                        }
                        query.Where(conditionals);
                    }
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TMMPurchaseApplyMainDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query
                                .Select((t, t0, t1, t2) => new TMMPurchaseApplyMainQueryModel
                    {
                        ID           = t.ID,
                        SourceId     = t.SourceId,
                        SourceNo     = t0.ProductionNo,
                        PurchaseNo   = t.PurchaseNo,
                        ApplyDate    = t.ApplyDate,
                        OperatorId   = t.OperatorId,
                        OperatorName = t1.AccountName,
                        OperatorTime = t.OperatorTime,
                        AuditId      = t.AuditId,
                        AuditName    = t2.AccountName,
                        AuditStatus  = t.AuditStatus,
                        AuditTime    = t.AuditTime,
                        CompanyId    = t.CompanyId,
                        DeleteFlag   = t.DeleteFlag,
                        TransferFlag = t.TransferFlag,
                    })
                                .Where((t) => !t.DeleteFlag && t.CompanyId == currentUser.CompanyID)
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query
                                .Select((t, t0, t1, t2) => new TMMPurchaseApplyMainQueryModel
                    {
                        ID           = t.ID,
                        SourceId     = t.SourceId,
                        SourceNo     = t0.ProductionNo,
                        PurchaseNo   = t.PurchaseNo,
                        ApplyDate    = t.ApplyDate,
                        OperatorId   = t.OperatorId,
                        OperatorName = t1.AccountName,
                        OperatorTime = t.OperatorTime,
                        AuditId      = t.AuditId,
                        AuditName    = t2.AccountName,
                        AuditStatus  = t.AuditStatus,
                        AuditTime    = t.AuditTime,
                        CompanyId    = t.CompanyId,
                        DeleteFlag   = t.DeleteFlag,
                        TransferFlag = t.TransferFlag,
                    })
                                .Where((t) => !t.DeleteFlag && t.CompanyId == currentUser.CompanyID)
                                .ToListAsync();
                }

                //返回执行结果
                return(ResponseUtil <List <TMMPurchaseApplyMainQueryModel> > .SuccessResult(queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <List <TMMPurchaseApplyMainQueryModel> > .FailResult(null, ex.Message));
            }
        }
Пример #2
0
        /// <summary>
        /// 获取T_PM_PolicyCompany数据
        /// </summary>
        /// <param name="requestObject">返回响应结果对象,包括响应代码,查询操作结果</param>
        /// <returns></returns>
        public async Task <ResponseObject <List <TPMPolicyCompanyQueryModel> > > GetAsync(RequestGet requestObject)
        {
            try
            {
                List <TPMPolicyCompanyQueryModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber = -1;                    //总记录数
                var            query       = _db.Instance.Queryable <TPMPolicyCompanyDbModel>();
                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var conditionals = SqlSugarUtil.GetConditionalModels(requestObject.QueryConditions);
                    query.Where(conditionals);
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TPMPolicyCompanyDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query.Select(
                        (t) => new TPMPolicyCompanyQueryModel
                    {
                        ID           = t.ID,
                        UserName     = t.UserName,
                        TelNumber    = t.TelNumber,
                        CompanyName  = t.CompanyName,
                        Industry     = t.Industry,
                        CompanyScale = t.CompanyScale,
                        CompanyOV    = t.CompanyOV,
                        RegisterTime = t.RegisterTime,
                    })
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query.Select(
                        (t) => new TPMPolicyCompanyQueryModel
                    {
                        ID           = t.ID,
                        UserName     = t.UserName,
                        TelNumber    = t.TelNumber,
                        CompanyName  = t.CompanyName,
                        Industry     = t.Industry,
                        CompanyScale = t.CompanyScale,
                        CompanyOV    = t.CompanyOV,
                        RegisterTime = t.RegisterTime,
                    })
                                .ToListAsync();
                }

                //返回执行结果
                return(ResponseUtil <List <TPMPolicyCompanyQueryModel> > .SuccessResult(queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <List <TPMPolicyCompanyQueryModel> > .FailResult(null, ex.Message));
            }
        }
Пример #3
0
        /// <summary>
        /// 新增T_BM_Package数据
        /// </summary>
        /// <param name="requestObject">返回响应结果对象,包括响应代码,新增操作结果</param>
        /// <returns></returns>
        public async Task <ResponseObject <bool> > PostAsync(RequestPost <TBMPackageAddModel> requestObject, CurrentUser currentUser)
        {
            try
            {
                var allDic  = BasicCacheGet.GetDic(currentUser);
                var dicUnit = allDic.Where(p => p.TypeName == "计量单位" && p.DicValue == "个").FirstOrDefault();
                if (dicUnit == null)
                {
                    return(ResponseUtil <bool> .FailResult(false, "请设置'个'的计量单位 "));
                }

                var MaterialTypeDic = allDic.Where(p => p.TypeName == "物料分类" && p.DicValue == "产品").FirstOrDefault();
                if (MaterialTypeDic == null)
                {
                    return(ResponseUtil <bool> .FailResult(false, "请设置'产品'的物料分类 "));
                }


                //如果没有新增数据,返回错误信息
                if (requestObject.PostData == null && requestObject.PostDataList == null)
                {
                    return(ResponseUtil <bool> .FailResult(false, "PostData不能都为null"));
                }
                var result = false;

                _db.Instance.BeginTran();
                //批量新增的优先级高于单条数据新增,且只会执行一个新增操作
                if (requestObject.PostDataList != null && requestObject.PostDataList.Count > 0)
                {
                }
                else
                {
                    bool isExistsName = _db.Instance.Queryable <TBMPackageDbModel>().Any(p => p.DicValue == requestObject.PostData.DicValue &&
                                                                                         p.DeleteFlag == false &&
                                                                                         p.CompanyId == currentUser.CompanyID);

                    if (isExistsName)
                    {
                        return(ResponseUtil <bool> .FailResult(false, "包型名称已经存在"));
                    }

                    bool isExistCode = _db.Instance.Queryable <TBMPackageDbModel>().Any(p => p.DicCode == requestObject.PostData.DicCode &&
                                                                                        p.DeleteFlag == false &&
                                                                                        p.CompanyId == currentUser.CompanyID);

                    if (isExistCode)
                    {
                        return(ResponseUtil <bool> .FailResult(false, "包型编码已经存在"));
                    }



                    //生成包型
                    var addModel = _mapper.Map <TBMPackageDbModel>(requestObject.PostData);
                    addModel.CompanyId  = currentUser.CompanyID;
                    addModel.DeleteFlag = false;
                    addModel.CreateId   = currentUser.UserID;
                    addModel.CreateTime = DateTime.Now;
                    int packageID = _db.Instance.Insertable(addModel).ExecuteReturnIdentity();

                    //生成物料
                    TBMMaterialFileDbModel material = new TBMMaterialFileDbModel();
                    material.MaterialCode   = CreateNo(currentUser.CompanyID);
                    material.BaseUnitId     = dicUnit.ID;
                    material.MaterialTypeId = MaterialTypeDic.ID;
                    material.MaterialName   = requestObject.PostData.DicValue;
                    material.DeleteFlag     = false;
                    material.CompanyId      = currentUser.CompanyID;
                    material.Remark         = "无配色方案";
                    material.PackageID      = packageID;

                    int MaterialId = _db.Instance.Insertable(material).ExecuteReturnIdentity();

                    _db.Instance.CommitTran();

                    _mService.ClearCache(currentUser);
                }
                //返回执行结果
                return(ResponseUtil <bool> .SuccessResult(true));
            }
            catch (Exception ex)
            {
                _db.Instance.RollbackTran();
                //返回异常结果
                return(ResponseUtil <bool> .FailResult(false, ex.Message));
            }
        }
        /// <summary>
        /// 生产入库态势(月)
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <ProductionWarehousingModel> > GetProductionWarehousingMonth(CurrentUser currentUser)
        {
            try
            {
                DateTime _thisDateTime = DateTime.Now;
                String   y             = _thisDateTime.ToString("yyyy");
                String   m             = _thisDateTime.ToString("MM");
                int      day           = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                //                var queryData = _db.Instance.Queryable<TWMProductionWhMainDbModel>()
                //.Where(t => t.CompanyId == currentUser.CompanyID && t.AuditStatus == 2 && t.DeleteFlag == false);
                string s1 = "";
                string s2 = "";
                for (int i = 0; i < 12; i++)
                {
                    s1 += "|" + (i + 1);
                    var      Month = (y + "-" + (i + 1));
                    DateTime dt1   = Convert.ToDateTime("" + y + "-" + (i + 1) + "-01");
                    DateTime dt2;
                    if ((i + 1) == 12)
                    {
                        dt2 = Convert.ToDateTime("" + (Convert.ToInt32(y) + 1) + "-01-01");
                    }
                    else
                    {
                        dt2 = Convert.ToDateTime("" + y + "-" + (i + 2) + "-01");
                    }
                    //            var query = await queryData.Where(t => t.WarehousingDate >= dt1 && t.WarehousingDate < dt2
                    //).Select(t => SqlFunc.AggregateSum(t.Number)).ToListAsync();
                    //            if (query.Count > 0)
                    //            {
                    //                s2 += "," + String.Format("{0:N2}", query[0]);
                    //            }
                    //            else
                    //            {
                    //                s2 += ", " + queryData.Where(t => t.WarehousingDate >= dt1 && t.WarehousingDate < dt2
                    //).Select(t => SqlFunc.AggregateSum(t.Number)).ToSql();
                    //            }

                    var today = await _db.Instance.Queryable <TWMProductionWhMainDbModel>()
                                .Where(t => t.CompanyId == currentUser.CompanyID && t.AuditStatus == 2 && t.DeleteFlag == false &&
                                       t.WarehousingDate >= dt1 && t.WarehousingDate < dt2
                                       ).Select(t => SqlFunc.AggregateSum(t.Number)).ToListAsync();

                    if (today.Count > 0)
                    {
                        s2 += "|" + String.Format("{0:N2}", today[0]);
                    }
                    else
                    {
                        s2 += "|0.00";
                    }
                }
                ProductionWarehousingModel _model = new ProductionWarehousingModel {
                    xAxisData = s1.Substring(1).Split('|'), SeriesData = s2.Substring(1).Split('|')
                };
                return(ResponseUtil <ProductionWarehousingModel> .SuccessResult(_model));
            }
            catch (Exception ex)
            {
                return(ResponseUtil <ProductionWarehousingModel>
                       .FailResult(null, $"生产入库态势(月) 发生异常{System.Environment.NewLine} {ex.Message}"));
            }
        }
        /// <summary>
        /// 生产车间入库数量
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <List <ProductionOrderWorkshopCountModel> > > GetProductionOrderWorkshop(CurrentUser currentUser)
        {
            try
            {
                List <ProductionOrderWorkshopCountModel> queryData = null;//查询结果集对象
                var query1 = _db.Instance.Queryable <TMMProductionOrderDetailDbModel, TMMProductionOrderMainDbModel, TBMDictionaryDbModel>(
                    (t1, t2, t3) => new object[]
                {
                    JoinType.Left, t1.MainId == t2.ID,
                    JoinType.Left, t1.WorkshopId == t3.ID
                }
                    ).Where((t1, t2, t3) => t2.CompanyId == currentUser.CompanyID
                            )
                             .GroupBy((t1, t2, t3) => new { t2.ID, t1.WorkshopId, t3.DicValue })
                             .Select((t1, t2, t3) => new ProductionOrderWorkshopCountModel1 {
                    ID = t2.ID, WorkshopId = Convert.ToInt32(t1.WorkshopId), WorkshopName = t3.DicValue
                });

                var s1     = query1.ToListAsync();
                var query2 = _db.Instance.Queryable <TMMWhApplyMainDbModel, TMMWhApplyDetailDbModel>(
                    (t1, t2) => new object[]
                {
                    JoinType.Left, t1.ID == t2.MainId
                }
                    ).Where((t1, t2) => t1.CompanyId == currentUser.CompanyID && t1.AuditStatus == 2 && t1.DeleteFlag == false
                            )
                             .GroupBy((t1, t2) => new { t1.SourceId, t1.ID })
                             .Select((t1, t2) => new ProductionOrderWorkshopCountModel2 {
                    ID = t1.ID, SourceId = Convert.ToInt32(t1.SourceId), Number = SqlFunc.AggregateSum(t2.ApplyNum)
                });

                var s2     = query2.ToListAsync();
                var ss2    = query2.ToSql();
                var query3 = _db.Instance.Queryable <TWMProductionWhMainDbModel>().Where(t1 => t1.CompanyId == currentUser.CompanyID && t1.AuditStatus == 2 && t1.DeleteFlag == false &&
                                                                                         t1.WarehousingDate == Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"))
                                                                                         )
                             .GroupBy(t => t.SourceId).Select(t => new ProductionOrderWorkshopCountModel3 {
                    SourceId = t.SourceId, Number = SqlFunc.AggregateSum(t.Number)
                });
                var s3        = query3.ToListAsync();
                var ss3       = query3.ToSql();
                var truequery = _db.Instance.Queryable(query2, query3, JoinType.Inner, (p1, p2) => p1.ID == p2.SourceId)
                                .Select((p1, p2) => new ProductionOrderWorkshopCountModel2 {
                    ID = p1.ID, SourceId = p1.SourceId, Number = p2.Number
                });
                var s4  = truequery.ToListAsync();
                var ss4 = truequery.ToSql();



                var ts = _db.Instance.Queryable(query1, truequery, JoinType.Inner, (p1, p2) => p1.ID == p2.SourceId);

                var Count = ts
                            .Where((p1, p2) => p1.WorkshopName != null)
                            .Select((p1, p2) => SqlFunc.AggregateSum(p2.Number));
                var Count1 = Count.ToListAsync().Result[0];

                queryData = await ts
                            .GroupBy((p1, p2) => p1.WorkshopName)
                            .Where((p1, p2) => p1.WorkshopName != null)
                            .Select((p1, p2) => new ProductionOrderWorkshopCountModel
                {
                    Name        = p1.WorkshopName,
                    Value       = SqlFunc.AggregateSum(p2.Number),
                    NumberCount = Count1
                }).ToListAsync();

                return(ResponseUtil <List <ProductionOrderWorkshopCountModel> > .SuccessResult(queryData));
            }
            catch (Exception ex)
            {
                return(ResponseUtil <List <ProductionOrderWorkshopCountModel> >
                       .FailResult(null, $"生产车间入库数量发生异常{System.Environment.NewLine} {ex.Message}"));
            }
        }
Пример #6
0
        private async Task <ResponseObject <List <TSSMSalesOrderDetailQueryNPModel> > > QueryDetailListAsync(int requestObject)
        {
            try
            {
                //查询结果集对象
                List <TSSMSalesOrderDetailQueryNPModel> queryData = null;
                //总记录数
                RefAsync <int> totalNumber = -1;
                var            query       = _db.Instance.Queryable <TSSMSalesOrderDetailDbModel>();

                //执行查询
                queryData = await _db.Instance.Queryable <TSSMSalesOrderDetailDbModel, TBMMaterialFileDbModel,
                                                          TBMDictionaryDbModel, TBMDictionaryDbModel, TBMDictionaryDbModel, TBMDictionaryDbModel, TBMDictionaryDbModel,
                                                          TBMPackageDbModel, TMMColorSolutionMainDbModel, TBMDictionaryDbModel>
                            (
                    (t, t0, t1, t2, t3, t4, t5, t6, t7, t8) => new object[]
                {
                    JoinType.Left, t.MaterialId == t0.ID,
                    JoinType.Left, t0.MaterialTypeId == t1.ID,
                    JoinType.Left, t0.ColorId == t2.ID,
                    JoinType.Left, t0.BaseUnitId == t3.ID,
                    JoinType.Left, t0.SalesUnitId == t4.ID,
                    JoinType.Left, t0.WarehouseUnitId == t5.ID,
                    JoinType.Left, t.PackageId == t6.ID,
                    JoinType.Left, t.ColorSolutionId == t7.ID,
                    JoinType.Left, t0.ProduceUnitId == t8.ID
                }
                            )
                            .Where(t => t.MainId == requestObject)
                            .Select((t, t0, t1, t2, t3, t4, t5, t6, t7, t8) => new TSSMSalesOrderDetailQueryNPModel
                {
                    ID                = t.ID,
                    MainId            = t.MainId,
                    MaterialId        = t.MaterialId,
                    MaterialCode      = t0.MaterialCode,
                    MaterialName      = t0.MaterialName,
                    MaterialTypeId    = t0.MaterialTypeId,
                    MaterialTypeName  = t1.DicValue,
                    ColorId           = t0.ColorId,
                    ColorName         = t2.DicValue,
                    Spec              = t0.Spec,
                    BaseUnitId        = t0.BaseUnitId,
                    BaseUnitName      = t3.DicValue,
                    SalesUnitId       = t0.SalesUnitId,
                    SalesUnitName     = SqlFunc.IsNullOrEmpty(t4.ID) ? t3.DicValue : t4.DicValue,
                    SalesRate         = t0.SalesRate,
                    GoodsCode         = t.GoodsCode,
                    GoodsName         = t.GoodsName,
                    UnitPrice         = t.UnitPrice,
                    SalesNum          = t.SalesNum,
                    SalesAmount       = t.SalesAmount,
                    DeliveryPeriod    = t.DeliveryPeriod,
                    TransferNum       = t.TransferNum,
                    Remark            = t.Remark,
                    WarehouseRate     = t0.WarehouseRate,
                    WarehouseUnitId   = t0.WarehouseUnitId,
                    WarehouseUnitName = SqlFunc.IsNullOrEmpty(t5.ID) ? t3.DicValue : t5.DicValue,
                    TransProdNum      = t.TransProdNum,
                    ProduceUnitId     = t0.ProduceUnitId,
                    ProduceUnitName   = SqlFunc.IsNullOrEmpty(t8.ID) ? t3.DicValue : t8.DicValue,
                    ProduceRate       = t0.ProduceRate
                })
                            .ToListAsync();

                //计算已发和待出库数量
                var dataList = await _db.Instance.Queryable <TWMSalesMainDbModel, TWMSalesDetailDbModel>(
                    (t, t0) => new object[]
                {
                    JoinType.Left, t.ID == t0.MainId
                })
                               .Where((t, t0) => t.SourceId == requestObject && SqlFunc.IsNull(t.DeleteFlag, false) == false)
                               .Select((t, t0) => new { t.ID, t.AuditStatus, t0.MaterialId, t0.ActualNum })
                               .ToListAsync();

                queryData.ForEach(p =>
                {
                    p.AlreadyNum = dataList.Where(p1 => p1.AuditStatus == 2 && p1.MaterialId == p.MaterialId).Sum(p2 => p2.ActualNum);
                    p.WaitNum    = dataList.Where(p1 => (p1.AuditStatus == null || p1.AuditStatus != 2) && p1.MaterialId == p.MaterialId).Sum(p2 => p2.ActualNum);
                });

                //返回执行结果
                return(ResponseUtil <List <TSSMSalesOrderDetailQueryNPModel> > .SuccessResult(queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <List <TSSMSalesOrderDetailQueryNPModel> > .FailResult(null, ex.Message));
            }
        }
Пример #7
0
        /// <summary>
        /// 获取T_SSM_SalesOrderMain主表数据数据
        /// </summary>
        /// <param name="requestObject">Get请求参数</param>
        /// <param name="currentUser"></param>
        /// <returns>返回响应结果对象,包括响应代码,查询操作结果</returns>
        public async Task <ResponseObject <List <TSSMSalesOrderMainQueryNPModel> > > GetMainListAsync(RequestGet requestObject, CurrentUser currentUser)
        {
            try
            {
                List <TSSMSalesOrderMainQueryNPModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber = -1;                        //总记录数
                var            query       = _db.Instance.Queryable <TSSMSalesOrderMainDbModel, TBMCustomerFileDbModel, TSMUserAccountDbModel,
                                                                     TBMDictionaryDbModel, TBMDictionaryDbModel, TSMUserAccountDbModel, TSMUserAccountDbModel>
                                             (
                    (t, t0, t1, t2, t3, t4, t5) => new object[]
                {
                    JoinType.Left, t.CustomerId == t0.ID,
                    JoinType.Left, t.SalesmanId == t1.ID,
                    JoinType.Left, t.OrderTypeId == t2.ID,
                    JoinType.Left, t.SettlementTypeId == t3.ID,
                    JoinType.Left, t.AuditId == t4.ID,
                    JoinType.Left, t.OperatorId == t5.ID
                }
                                             ).Where((t, t0, t1, t2, t3, t4, t5) => t.DeleteFlag == false && SqlFunc.IsNull(t.IsMaterial, false) == true);
                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    //只能查询主表数据,且主表别名必须是t
                    var conditionals = SqlSugarUtil.GetConditionalModels(requestObject.QueryConditions);
                    foreach (ConditionalModel item in conditionals)
                    {
                        if (item.FieldName.ToLower() == "customername")
                        {
                            item.FieldName = $"t0.{item.FieldName}";
                            continue;
                        }
                        item.FieldName = $"t.{item.FieldName}";
                    }
                    query.Where(conditionals);
                }

                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TSSMSalesOrderMainDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" && item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query
                                .Select((t, t0, t1, t2, t3, t4, t5) => new TSSMSalesOrderMainQueryNPModel
                    {
                        ID                = t.ID,
                        CustomerId        = t.CustomerId,
                        CustomerName      = t0.CustomerName,
                        SalesmanId        = t.SalesmanId,
                        SalesmanName      = t1.AccountName,
                        OrderNo           = t.OrderNo,
                        OrderTypeId       = t.OrderTypeId,
                        OrderTypeName     = t2.DicValue,
                        SettlementTypeId  = t.SettlementTypeId,
                        SettementTypeName = t3.DicValue,
                        Currency          = t.Currency,
                        ReceiptAddress    = t.ReceiptAddress,
                        OrderDate         = t.OrderDate,
                        AuditStatus       = t.AuditStatus,
                        AuditId           = t.AuditId,
                        AuditName         = t4.AccountName,
                        AuditTime         = t.AuditTime,
                        OperatorId        = t.OperatorId,
                        OperatorName      = t5.AccountName,
                        ContactName       = t.ContactName,
                        ContactNumber     = t.ContactNumber,
                        CompanyId         = t.CompanyId,
                        DeleteFlag        = t.DeleteFlag,
                        TransferStatus    = t.TransferStatus,
                        SalesAmount       = t.SalesAmount,
                        SalesNum          = t.SalesNum,
                        TransProdStatus   = t.TransProdStatus
                    })
                                .Where(t => t.CompanyId == currentUser.CompanyID && !t.DeleteFlag)
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query
                                .Select((t, t0, t1, t2, t3, t4, t5) => new TSSMSalesOrderMainQueryNPModel
                    {
                        ID                = t.ID,
                        CustomerId        = t.CustomerId,
                        CustomerName      = t0.CustomerName,
                        SalesmanId        = t.SalesmanId,
                        SalesmanName      = t1.AccountName,
                        OrderNo           = t.OrderNo,
                        OrderTypeId       = t.OrderTypeId,
                        OrderTypeName     = t2.DicValue,
                        SettlementTypeId  = t.SettlementTypeId,
                        SettementTypeName = t3.DicValue,
                        Currency          = t.Currency,
                        ReceiptAddress    = t.ReceiptAddress,
                        OrderDate         = t.OrderDate,
                        AuditStatus       = t.AuditStatus,
                        AuditId           = t.AuditId,
                        AuditName         = t4.AccountName,
                        AuditTime         = t.AuditTime,
                        OperatorId        = t.OperatorId,
                        OperatorName      = t5.AccountName,
                        ContactName       = t.ContactName,
                        ContactNumber     = t.ContactNumber,
                        CompanyId         = t.CompanyId,
                        DeleteFlag        = t.DeleteFlag,
                        TransferStatus    = t.TransferStatus,
                        SalesAmount       = t.SalesAmount,
                        SalesNum          = t.SalesNum,
                        TransProdStatus   = t.TransProdStatus
                    })
                                .Where(t => t.CompanyId == currentUser.CompanyID && !t.DeleteFlag)
                                .ToListAsync();
                }

                //是否可编辑
                queryData.ForEach(p => p.AllowEdit = p.AuditStatus != 2 && p.OperatorId == currentUser.UserID);

                //返回执行结果
                return(ResponseUtil <List <TSSMSalesOrderMainQueryNPModel> > .SuccessResult(queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <List <TSSMSalesOrderMainQueryNPModel> > .FailResult(null, ex.Message));
            }
        }
Пример #8
0
        /// <summary>
        /// 获取树结构数据
        /// </summary>
        /// <param name="requestObject">Get请求参数</param>
        /// <returns>返回响应结果对象,包括响应代码,查询操作结果</returns>
        public async Task <ResponseObject <TDataDicMainModel, List <DataTreeNode> > > GetTreeAsync(RequestObject <TDataDicMainModel> requestObject)
        {
            try
            {
                List <TDataDicMainModel> queryData = null;//查询结果集对象

                List <DataTreeNode> result      = new List <DataTreeNode>();
                RefAsync <int>      totalNumber = -1;//总记录数
                var query = _db.Instance.Queryable <TDataDicMainModel, TPMMenusDbModel, TUsersModel, TDataDicDetailModel>(
                    (t, t1, t2, t3) => new object[]
                {
                    JoinType.Inner, t.MenuId == t1.Id,
                    JoinType.Left, t.CreateId == t2.Id,
                    JoinType.Left, t3.KeyId == t.Id
                });
                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var expressionList = SqlSugarUtil.GetQueryExpressions(requestObject.QueryConditions);
                    expressionList.ForEach(p => query.Where($"t.{p}"));
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    requestObject.OrderByConditions.ForEach(p => query.OrderBy($"{p.Column} {p.Condition}"));
                }

                var queryResult = await query.Select((t, t1, t2, t3) => new { main = t, deatail = t3 }).ToListAsync();

                foreach (var item in queryResult.Select(p => p.main.Id).Distinct().OrderBy(p => p))
                {
                    var temp = queryResult.Where(p => p.main.Id == item).Select(p => p.main).FirstOrDefault();

                    DataTreeNode dataTreeNode = new DataTreeNode();
                    dataTreeNode.ID       = temp.Id;
                    dataTreeNode.Name     = temp.Key;
                    dataTreeNode.Children = new List <DataTreeNode>();
                    dataTreeNode.Type     = 1;
                    dataTreeNode.ParentID = -1;
                    dataTreeNode.MenuID   = temp.MenuId;

                    var childList = queryResult.Where(p => p.main.Id == temp.Id).Select(p => p.deatail);

                    foreach (var childItem in childList.Where(p => p.Id > 0))
                    {
                        DataTreeNode cdataTreeNode = new DataTreeNode();
                        cdataTreeNode.ID       = childItem.Id;
                        cdataTreeNode.Name     = childItem.Value;
                        cdataTreeNode.Children = new List <DataTreeNode>();
                        dataTreeNode.ParentID  = temp.Id;
                        dataTreeNode.Type      = 2;

                        dataTreeNode.Children.Add(cdataTreeNode);
                    }

                    result.Add(dataTreeNode);
                }

                //返回执行结果
                return(ResponseUtil <TDataDicMainModel, List <DataTreeNode> > .SuccessResult(requestObject, result, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <TDataDicMainModel, List <DataTreeNode> > .FailResult(requestObject, null, ex.Message));
            }
        }
Пример #9
0
        /// <summary>
        /// 获取T_DataDicMain数据
        /// </summary>
        /// <param name="requestObject">Get请求参数</param>
        /// <returns>返回响应结果对象,包括响应代码,查询操作结果</returns>
        public async Task <ResponseObject <TDataDicMainModel, List <TDataDicMainModel> > > GetAsync(RequestObject <TDataDicMainModel> requestObject)
        {
            try
            {
                List <TDataDicMainModel> queryData   = null; //查询结果集对象
                RefAsync <int>           totalNumber = -1;   //总记录数
                var query = _db.Instance.Queryable <TDataDicMainModel, TPMMenusDbModel, TUsersModel>(
                    (t, t1, t2) => new object[]
                {
                    JoinType.Left, t.MenuId == t1.Id,
                    JoinType.Left, t.CreateId == t2.Id,
                });
                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var expressionList = SqlSugarUtil.GetQueryExpressions(requestObject.QueryConditions);
                    expressionList.ForEach(p => query.Where($"t.{p}"));
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    requestObject.OrderByConditions.ForEach(p => query.OrderBy($"{p.Column} {p.Condition}"));
                }

                //设置多表查询返回实体类
                query.Select((t, t1, t2) => new TDataDicMainModel
                {
                    Id             = t.Id,
                    MenuId         = t.MenuId,
                    TMenusMenuName = t1.MenuName,
                    Key            = t.Key,
                    CreateTime     = t.CreateTime,
                    CreateId       = t.CreateId,
                    TUsersUserName = t2.UserName
                });

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query.ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query.ToListAsync();
                }

                //查询明细数据
                if (queryData != null && queryData.Count > 0)
                {
                    var detailQuery = _db.Instance.Queryable <TDataDicDetailModel, TDataDicMainModel, TUsersModel>(
                        (t, t0, t1) => new object[]
                    {
                        JoinType.Left, t.KeyId == t0.Id,
                        JoinType.Left, t.CreateId == t1.Id,
                    });
                    detailQuery.In(t => t.KeyId, queryData.Select(p => p.Id).ToList());
                    detailQuery.Select((t, t0, t1) => new TDataDicDetailModel
                    {
                        Id              = t.Id,
                        KeyId           = t.KeyId,
                        TDataDicMainKey = t0.Key,
                        Value           = t.Value,
                        CreateTime      = t.CreateTime,
                        CreateId        = t.CreateId
                    });
                    var sql     = detailQuery.ToSql();
                    var details = await detailQuery.ToListAsync();

                    queryData.ForEach(p => p.ChildList = details.Where(p1 => p1.KeyId == p.Id).ToList());
                }

                //返回执行结果
                return(ResponseUtil <TDataDicMainModel, List <TDataDicMainModel> > .SuccessResult(requestObject, queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <TDataDicMainModel, List <TDataDicMainModel> > .FailResult(requestObject, null, ex.Message));
            }
        }
        /// <summary>
        /// 复制物料
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <bool> > Copy(TBMMaterialFileCopyModel copyModel, CurrentUser currentUser)
        {
            try
            {
                _db.Instance.BeginTran();

                foreach (var ID in copyModel.Ids)
                {
                    TBMMaterialFileDbModel source = await _db.Instance.Queryable <TBMMaterialFileDbModel>().Where(p => p.ID == ID && p.CompanyId == currentUser.CompanyID).FirstAsync();

                    if (source.PackageID != null)
                    {
                        throw new Exception("包型对应的物料,不能复制");
                    }
                    if (source != null)
                    {
                        var sameName = _db.Instance.Queryable <TBMMaterialFileDbModel>().Where(p => p.MaterialName.StartsWith(source.MaterialName) && p.CompanyId == currentUser.CompanyID).ToList();
                        int index    = 1;

                        string aimName = string.Empty;

                        int len = source.MaterialName.Length + 4;
                        foreach (var item in sameName.Where(p => p.MaterialName != source.MaterialName).OrderBy(p => p.MaterialName))
                        {
                            if (item.MaterialName.Length <= len)
                            {
                                continue;
                            }

                            string tempName = item.MaterialName.Substring(len);

                            if (int.TryParse(tempName, out index))
                            {
                                index++;
                                aimName = string.Concat(source.MaterialName, "copy", index.ToString().PadLeft(2, '0'));

                                if (sameName.Any(p => p.MaterialName == aimName))
                                {
                                    aimName = string.Empty;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        if (aimName == string.Empty)
                        {
                            aimName = string.Concat(source.MaterialName, "copy01");
                        }


                        var sameCode  = _db.Instance.Queryable <TBMMaterialFileDbModel>().Where(p => p.MaterialCode.StartsWith(source.MaterialCode) && p.CompanyId == currentUser.CompanyID).ToList();
                        int indexCode = 1;

                        string aimCode = string.Empty;

                        int lenCode = source.MaterialCode.Length + 4;
                        foreach (var item in sameCode.Where(p => p.MaterialCode != source.MaterialCode).OrderBy(p => p.MaterialCode))
                        {
                            if (item.MaterialCode.Length <= lenCode)
                            {
                                continue;
                            }
                            string tempCode = item.MaterialCode.Substring(lenCode);

                            if (int.TryParse(tempCode, out indexCode))
                            {
                                indexCode++;
                                aimCode = string.Concat(source.MaterialCode, "copy", indexCode.ToString().PadLeft(2, '0'));

                                if (sameCode.Any(p => p.MaterialCode == aimCode))
                                {
                                    aimCode = string.Empty;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }

                        if (aimCode == string.Empty)
                        {
                            aimCode = string.Concat(source.MaterialCode, "copy01");
                        }

                        if (aimName.Length > 50)
                        {
                            throw new Exception($"'{source.MaterialName}'物料名称复制后大于50,不允许复制");
                        }

                        if (aimCode.Length > 20)
                        {
                            throw new Exception($"'{source.MaterialCode}'物料代码复制后大于20,不允许复制");
                        }

                        source.MaterialCode = aimCode;
                        source.MaterialName = aimName;
                        source.ID           = 0;

                        _db.Instance.Insertable <TBMMaterialFileDbModel>(source).ExecuteCommand();
                    }
                }
                _db.Instance.CommitTran();
                ClearCache(currentUser);
                return(ResponseUtil <bool> .SuccessResult(true));
            }
            catch (Exception ex)
            {
                _db.Instance.RollbackTran();
                return(ResponseUtil <bool> .FailResult(false, ex.Message));
            }
        }
        /// <summary>
        /// 获取T_BM_MaterialFile数据
        /// </summary>
        /// <param name="requestObject">返回响应结果对象,包括响应代码,查询操作结果</param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <TBMMaterialFileQueryModel, List <TBMMaterialFileQueryModel> > > GetNoMemory(RequestObject <TBMMaterialFileQueryModel> requestObject, CurrentUser currentUser)
        {
            try
            {
                var tBMDictionaryDbModel = _db.Instance.Queryable <TBMDictionaryDbModel>().Where(p => p.CompanyId == currentUser.CompanyID).ToList().ToDictionary(p => p.ID, p => p.DicValue);

                List <TBMMaterialFileQueryModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber = -1;                   //总记录数
                var            query       = _db.Instance.Queryable <TBMMaterialFileDbModel, TBMDictionaryDbModel, TBMWarehouseFileDbModel>(
                    (t, t0, t1) => new object[]
                {
                    JoinType.Left, t.ColorId == t0.ID,
                    JoinType.Left, t.DefaultWarehouseId == t1.ID,
                }).Where((t, t0, t1) => t.CompanyId == currentUser.CompanyID && SqlFunc.IsNull(t.DeleteFlag, false) == false);
                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var conditionals = SqlSugarUtil.GetConditionalModels(requestObject.QueryConditions);
                    query.Where(conditionals);
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TBMMaterialFileDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query.Select(
                        (t, t0, t1) => new TBMMaterialFileQueryModel
                    {
                        ID                   = t.ID,
                        MaterialCode         = t.MaterialCode,
                        MaterialName         = t.MaterialName,
                        Spec                 = t.Spec,
                        ColorId              = t.ColorId,
                        ColorName            = t0.DicValue,
                        MaterialTypeId       = t.MaterialTypeId,
                        DefaultWarehouseId   = t.DefaultWarehouseId,
                        DefaultWarehouseName = t1.WarehouseName,
                        ShelfLife            = t.ShelfLife,
                        HighInventory        = t.HighInventory,
                        LowInventory         = t.LowInventory,
                        BaseUnitId           = t.BaseUnitId,
                        ProduceUnitId        = t.ProduceUnitId,
                        ProduceRate          = t.ProduceRate,
                        PurchaseUnitId       = t.PurchaseUnitId,
                        PurchaseRate         = t.PurchaseRate,
                        SalesUnitId          = t.SalesUnitId,
                        SalesRate            = t.SalesRate,
                        WarehouseUnitId      = t.WarehouseUnitId,
                        WarehouseRate        = t.WarehouseRate,
                        Remark               = t.Remark,
                        Url                  = t.Url,
                        ColorSolutionID      = t.ColorSolutionID,
                        PackageID            = t.PackageID
                    })
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query.Select(
                        (t, t0, t1) => new TBMMaterialFileQueryModel
                    {
                        ID                   = t.ID,
                        MaterialCode         = t.MaterialCode,
                        MaterialName         = t.MaterialName,
                        Spec                 = t.Spec,
                        ColorId              = t.ColorId,
                        ColorName            = t0.DicValue,
                        MaterialTypeId       = t.MaterialTypeId,
                        DefaultWarehouseId   = t.DefaultWarehouseId,
                        DefaultWarehouseName = t1.WarehouseName,
                        ShelfLife            = t.ShelfLife,
                        HighInventory        = t.HighInventory,
                        LowInventory         = t.LowInventory,
                        BaseUnitId           = t.BaseUnitId,
                        ProduceUnitId        = t.ProduceUnitId,
                        ProduceRate          = t.ProduceRate,
                        PurchaseUnitId       = t.PurchaseUnitId,
                        PurchaseRate         = t.PurchaseRate,
                        SalesUnitId          = t.SalesUnitId,
                        SalesRate            = t.SalesRate,
                        WarehouseUnitId      = t.WarehouseUnitId,
                        WarehouseRate        = t.WarehouseRate,
                        Remark               = t.Remark,
                        Url                  = t.Url,
                        ColorSolutionID      = t.ColorSolutionID,
                        PackageID            = t.PackageID
                    })
                                .ToListAsync();
                }

                queryData.ForEach((x) => {
                    if (tBMDictionaryDbModel.ContainsKey(x.BaseUnitId))
                    {
                        x.BaseUnitName = tBMDictionaryDbModel[x.BaseUnitId];
                    }

                    if (x.ProduceUnitId != null && tBMDictionaryDbModel.ContainsKey(x.ProduceUnitId.Value))
                    {
                        x.ProduceUnitName = tBMDictionaryDbModel[x.ProduceUnitId.Value];
                    }

                    if (x.PurchaseUnitId != null && tBMDictionaryDbModel.ContainsKey(x.PurchaseUnitId.Value))
                    {
                        x.PurchaseUnitName = tBMDictionaryDbModel[x.PurchaseUnitId.Value];
                    }

                    if (x.SalesUnitId != null && tBMDictionaryDbModel.ContainsKey(x.SalesUnitId.Value))
                    {
                        x.SalesUnitName = tBMDictionaryDbModel[x.SalesUnitId.Value];
                    }

                    if (x.WarehouseUnitId != null && tBMDictionaryDbModel.ContainsKey(x.WarehouseUnitId.Value))
                    {
                        x.WarehouseUnitName = tBMDictionaryDbModel[x.WarehouseUnitId.Value];
                    }

                    if (tBMDictionaryDbModel.ContainsKey(x.MaterialTypeId))
                    {
                        x.MaterialTypeName = tBMDictionaryDbModel[x.MaterialTypeId];
                    }
                });

                //返回执行结果
                return(ResponseUtil <TBMMaterialFileQueryModel, List <TBMMaterialFileQueryModel> > .SuccessResult(requestObject, queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <TBMMaterialFileQueryModel, List <TBMMaterialFileQueryModel> > .FailResult(requestObject, null, ex.Message));
            }
        }
        /// <summary>
        /// 新增T_BM_MaterialFile数据
        /// </summary>
        /// <param name="requestObject">返回响应结果对象,包括响应代码,新增操作结果</param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <TBMMaterialFileAddModel, bool> > PostAsync(RequestObject <TBMMaterialFileAddModel> requestObject, CurrentUser currentUser)
        {
            try
            {
                var dic = BasicCacheGet.GetDic(currentUser);
                //如果没有新增数据,返回错误信息
                if (requestObject.PostData == null && requestObject.PostDataList == null)
                {
                    return(ResponseUtil <TBMMaterialFileAddModel, bool> .FailResult(requestObject, false, "PostData不能都为null"));
                }
                var result = false;
                //批量新增的优先级高于单条数据新增,且只会执行一个新增操作
                if (requestObject.PostDataList != null && requestObject.PostDataList.Count > 0)
                {
                    //var addList = _mapper.Map<List<TBMMaterialFileAddModel>, List<TBMMaterialFileDbModel>>(requestObject.PostDataList);
                    //result = await _db.Instance.Insertable(addList).ExecuteCommandAsync() > 0;
                }
                else
                {
                    var addModel = _mapper.Map <TBMMaterialFileDbModel>(requestObject.PostData);

                    var oldModel = _db.Instance.Queryable <TBMMaterialFileDbModel>().Where(p => SqlFunc.IsNull(p.DeleteFlag, false) == false &&
                                                                                           p.CompanyId == currentUser.CompanyID && p.MaterialCode == addModel.MaterialCode).First();
                    if (oldModel != null)
                    {
                        return(ResponseUtil <TBMMaterialFileAddModel, bool> .FailResult(requestObject, false, addModel.MaterialCode + " 已经存在"));
                    }

                    if (addModel.ColorId != null)
                    {
                        var oldModel1 = _db.Instance.Queryable <TBMMaterialFileDbModel>().Where(p => SqlFunc.IsNull(p.DeleteFlag, false) == false &&
                                                                                                p.CompanyId == currentUser.CompanyID && p.MaterialName == addModel.MaterialName && p.ColorId == addModel.ColorId).First();
                        if (oldModel1 != null)
                        {
                            string colorName = "此颜色";

                            var colorEntity = dic.Where(p => p.ID == addModel.ColorId).FirstOrDefault();
                            if (null != colorEntity)
                            {
                                colorName = colorEntity.DicValue;
                            }

                            return(ResponseUtil <TBMMaterialFileAddModel, bool> .FailResult(requestObject, false, addModel.MaterialName + $" {colorName}已经存在"));
                        }
                    }

                    addModel.CompanyId = currentUser.CompanyID;

                    result = await _db.Instance.Insertable(addModel).ExecuteCommandAsync() > 0;
                }
                ClearCache(currentUser);

                //返回执行结果
                if (result)
                {
                    return(ResponseUtil <TBMMaterialFileAddModel, bool> .SuccessResult(requestObject, true));
                }
                return(ResponseUtil <TBMMaterialFileAddModel, bool> .FailResult(requestObject, false, "新增数据失败!"));
            }
            catch (Exception ex)
            {
                //返回异常结果
                return(ResponseUtil <TBMMaterialFileAddModel, bool> .FailResult(requestObject, false, ex.Message));
            }
        }
        /// <summary>
        /// 获取物料缓存
        /// </summary>
        /// <param name="requestObject"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <TBMMaterialFileQueryModel, List <TBMMaterialFileCacheModel> > > GetAsync(RequestObject <TBMMaterialFileQueryModel> requestObject, CurrentUser currentUser)
        {
            string key = string.Format(CacheKeyString.Material, currentUser.CompanyID);
            List <TBMMaterialFileCacheModel> result;

            try
            {
                //if (!_memoryCache.TryGetValue(key, out result))
                //{
                //    var tBMMaterialFileQueryList = await GetAllAsync(currentUser);
                //    result = tBMMaterialFileQueryList;
                //    _memoryCache.Set(key, tBMMaterialFileQueryList, new TimeSpan(2, 0, 0, 0));//缓存两天
                //}

                var redis = CacheFactory.Instance(CacheType.Redis);
                result = redis.GetValueByKey <List <TBMMaterialFileCacheModel> >(key, () =>
                {
                    var tBMMaterialFileQueryList = GetAllAsync(currentUser).Result;
                    return(tBMMaterialFileQueryList);
                }, 24 * 60 * 60 * 2);

                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    Expression <Func <TBMMaterialFileCacheModel, bool> > queryConditionLam = (x) => true;

                    var con1 = requestObject.QueryConditions.Where(p => p.Column.ToLower() == "materialcode" && !string.IsNullOrWhiteSpace(p.Content)).FirstOrDefault();
                    if (con1 != null)
                    {
                        requestObject.QueryConditions.Remove(con1);
                        queryConditionLam = queryConditionLam.And(x => x.MaterialCode.Contains(con1.Content) || x.MaterialName.Contains(con1.Content));
                    }

                    var con2 = requestObject.QueryConditions.Where(p => p.Column.ToLower() == "materialname" && !string.IsNullOrWhiteSpace(p.Content)).FirstOrDefault();
                    if (con2 != null)
                    {
                        requestObject.QueryConditions.Remove(con2);
                        queryConditionLam = queryConditionLam.And(x => x.MaterialCode.Contains(con2.Content) || x.MaterialName.Contains(con2.Content));
                    }

                    var conditionals = SqlSugarUtil.GetConditionalFull(requestObject.QueryConditions).Where(p => !string.IsNullOrWhiteSpace(p.FieldValue)).ToList();

                    var whereConditional = ConditionalModelToExpression.BuildExpression <TBMMaterialFileCacheModel>(conditionals);
                    queryConditionLam = queryConditionLam.And(whereConditional);
                    result            = result.Where(queryConditionLam.Compile()).ToList();
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TBMMaterialFileDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        //query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                int totalNum = 0;
                if (requestObject.IsPaging)
                {
                    totalNum = result.Count();

                    result = result.OrderBy(p => p.ID).Skip(requestObject.PageSize * (requestObject.PageIndex - 1)).Take(requestObject.PageSize).ToList();
                }
                else
                {
                    result = result.ToList();
                }

                return(ResponseUtil <TBMMaterialFileQueryModel, List <TBMMaterialFileCacheModel> > .SuccessResult(requestObject, result, totalNum));
            }
            catch (Exception ex)
            {
                return(ResponseUtil <TBMMaterialFileQueryModel, List <TBMMaterialFileCacheModel> > .FailResult(requestObject, null, ex.Message));
            }
        }
        /// <summary>
        /// 获取T_BM_SupplierFile主表数据数据
        /// </summary>
        /// <param name="requestObject">Get请求参数</param>
        /// <returns>返回响应结果对象,包括响应代码,查询操作结果</returns>
        public async Task <ResponseObject <List <TBMSupplierFileQueryModel> > > GetMainListAsync(RequestGet requestObject, CurrentUser currentUser)
        {
            try
            {
                List <TBMSupplierFileQueryModel> queryData = new List <TBMSupplierFileQueryModel>(); //查询结果集对象
                RefAsync <int> totalNumber = -1;                                                     //总记录数

                var query = _db.Instance.Queryable <TBMSupplierFileDbModel>().Where(t => t.CompanyId == currentUser.CompanyID && t.DeleteFlag == false);

                //var zx= SqlFunc.Subqueryable<TBMSupplierContactDbModel>().Where(s => s.SupplierId == t.ID && s.ContactName == "123").Any();

                //数据字典
                List <TBMDictionaryCacheModel> dics  = BasicCacheGet.GetDic(currentUser);
                List <ChinaAreaRecord>         Areas = BasicCacheGet.GetChinaArea(currentUser);

                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var customerConditions1 = requestObject.QueryConditions.Where(p => p.Column.ToLower() == "contactname").ToList();
                    if (customerConditions1 != null && customerConditions1.Count() > 0)
                    {
                        var thisC = customerConditions1.FirstOrDefault();
                        query = query.Where(t => SqlFunc.Subqueryable <TBMSupplierContactDbModel>().Where(s => s.SupplierId == t.ID && s.ContactName.Contains(thisC.Content)).Any());
                    }

                    var customerConditions2 = requestObject.QueryConditions.Where(p => p.Column.ToLower() != "contactname").ToList();
                    if (customerConditions2 != null && customerConditions2.Count() > 0)
                    {
                        var conditionals = SqlSugarUtil.GetConditionalModels(customerConditions2);
                        query.Where(conditionals);
                    }
                }

                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TBMSupplierFileDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                List <TBMSupplierFileDbModel> queryDataTemp;
                //执行查询
                if (requestObject.IsPaging)
                {
                    queryDataTemp = await query
                                    .Where(t => !t.DeleteFlag)
                                    .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryDataTemp = await query
                                    .Where(t => !t.DeleteFlag)
                                    .ToListAsync();
                }

                queryDataTemp.ForEach((x) =>
                {
                    var itemEnity       = ExpressionGenericMapper <TBMSupplierFileDbModel, TBMSupplierFileQueryModel> .Trans(x);
                    itemEnity.ChildList = new List <TBMSupplierContactQueryModel>();
                    foreach (var citem in x.Child.OrderBy(p => p.Priority))
                    {
                        var citemEnity = ExpressionGenericMapper <TBMSupplierContactDbModel, TBMSupplierContactQueryModel> .Trans(citem);
                        itemEnity.ChildList.Add(citemEnity);
                    }

                    var item = dics.Where(p => p.ID == x.SupplierTypeId).FirstOrDefault();
                    if (item != null)
                    {
                        itemEnity.SupplierTypeName = item.DicValue;
                    }

                    if (x.IndustryId != null)
                    {
                        var industry = dics.Where(p => p.ID == x.IndustryId).FirstOrDefault();
                        if (x.IndustryId != null)
                        {
                            itemEnity.IndustryName = industry?.DicValue;
                        }
                    }

                    if (!string.IsNullOrEmpty(x.City))
                    {
                        var cityEntity     = Areas.Where(p => p.Code == x.City).FirstOrDefault();
                        itemEnity.CityName = cityEntity?.FullName;
                    }

                    queryData.Add(itemEnity);
                });

                //返回执行结果
                return(ResponseUtil <List <TBMSupplierFileQueryModel> > .SuccessResult(queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <List <TBMSupplierFileQueryModel> > .FailResult(null, ex.Message));
            }
        }
        /// <summary>
        /// 获取T_MM_BOMTempMain主表数据数据
        /// </summary>
        /// <param name="requestObject">Get请求参数</param>
        /// <param name="currentUser"></param>
        /// <returns>返回响应结果对象,包括响应代码,查询操作结果</returns>
        public async Task <ResponseObject <List <TMMBOMTempMainQueryModel> > > GetMainListAsync(RequestGet requestObject, CurrentUser currentUser)
        {
            try
            {
                List <TMMBOMTempMainQueryModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber = -1;                  //总记录数
                var            query       = _db.Instance.Queryable <TMMBOMTempMainDbModel>().Where(p => p.CompanyId == currentUser.CompanyID);
                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var conditionals = SqlSugarUtil.GetConditionalModels(requestObject.QueryConditions);
                    query.Where(conditionals);
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TMMBOMTempMainDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query.Select((t) => new TMMBOMTempMainQueryModel
                    {
                        ID           = t.ID,
                        PackageId    = t.PackageId,
                        PagerCode    = t.PagerCode,
                        Maker        = t.Maker,
                        FrontImgPath = t.FrontImgPath,
                        SideImgPath  = t.SideImgPath,
                        BackImgPath  = t.BackImgPath,
                        TempName     = t.TempName,
                    })
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query.Select((t) => new TMMBOMTempMainQueryModel
                    {
                        ID           = t.ID,
                        PackageId    = t.PackageId,
                        PagerCode    = t.PagerCode,
                        Maker        = t.Maker,
                        FrontImgPath = t.FrontImgPath,
                        SideImgPath  = t.SideImgPath,
                        BackImgPath  = t.BackImgPath,
                        TempName     = t.TempName,
                    })
                                .ToListAsync();
                }

                //返回执行结果
                return(ResponseUtil <List <TMMBOMTempMainQueryModel> > .SuccessResult(queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <List <TMMBOMTempMainQueryModel> > .FailResult(null, ex.Message));
            }
        }
        /// <summary>
        /// 新增T_MM_ColorSolutionMain数据
        /// </summary>
        /// <param name="requestObject">Post请求参数</param>
        /// <returns>返回响应结果对象,包括响应代码,新增操作结果</returns>
        public async Task <ResponseObject <bool> > PostAsync(RequestPost <TMMColorSolutionMainAddNewModel> requestObject, CurrentUser currentUser)
        {
            var currDb = _db.Instance;//事务需要使用同一个 SqlSugarClient对象实例

            try
            {
                //没有新增数据,返回错误信息
                if (requestObject.PostData == null)
                {
                    return(ResponseUtil <bool> .FailResult(false, "PostData不能为null"));
                }


                var allDic  = BasicCacheGet.GetDic(currentUser);
                var dicUnit = allDic.Where(p => p.TypeName == "计量单位" && p.DicValue == "个").FirstOrDefault();
                if (dicUnit == null)
                {
                    return(ResponseUtil <bool> .FailResult(false, "请设置'个'的计量单位 "));
                }

                var MaterialTypeDic = allDic.Where(p => p.TypeName == "物料分类" && p.DicValue == "产品").FirstOrDefault();
                if (MaterialTypeDic == null)
                {
                    return(ResponseUtil <bool> .FailResult(false, "请设置'产品'的物料分类 "));
                }

                //开启事务
                currDb.BeginTran();
                //插入主表数据
                var mapMainModel = _mapper.Map <TMMColorSolutionMainDbModel>(requestObject.PostData);
                if (_db.Instance.Queryable <TMMColorSolutionMainDbModel>().Any(p => p.SolutionCode == requestObject.PostData.SolutionCode && p.PackageId == requestObject.PostData.PackageId &&
                                                                               p.DeleteFlag == false && p.CompanyId == currentUser.CompanyID))
                {
                    throw new Exception("编号重复");
                }

                mapMainModel.CompanyId = currentUser.CompanyID;
                var mainId = await currDb.Insertable(mapMainModel).ExecuteReturnIdentityAsync();

                TBMPackageDbModel tBMPackageDbModel = _db.Instance.Queryable <TBMPackageDbModel>().Where(p => p.ID == requestObject.PostData.PackageId).First();

                if (!_db.Instance.Queryable <TBMMaterialFileDbModel>().Any(p => p.ColorId == mapMainModel.ColorId && p.PackageID == tBMPackageDbModel.ID))
                {
                    //生成物料
                    TBMMaterialFileDbModel material = new TBMMaterialFileDbModel();
                    material.MaterialCode    = CreateNo(currentUser.CompanyID);
                    material.ColorId         = mapMainModel.ColorId;
                    material.BaseUnitId      = dicUnit.ID;
                    material.MaterialTypeId  = MaterialTypeDic.ID;
                    material.MaterialName    = tBMPackageDbModel.DicValue;
                    material.DeleteFlag      = false;
                    material.CompanyId       = currentUser.CompanyID;
                    material.ColorSolutionID = mainId;
                    material.PackageID       = requestObject.PostData.PackageId;
                    material.Remark          = requestObject.PostData.SolutionCode;
                    _db.Instance.Insertable(material).ExecuteReturnIdentity();
                }

                ClearCache(currentUser);//更新缓存

                //更新明细表外键ID值
                requestObject.PostData.ChildList.ForEach(p => p.MainId = mainId);
                //插入从表数据
                var mapDetailModelList = _mapper.Map <List <TMMColorSolutionDetailAddNewModel>, List <TMMColorSolutionDetailDbModel> >(requestObject.PostData.ChildList);
                var result             = await currDb.Insertable(mapDetailModelList).ExecuteCommandAsync() > 0;

                //提交事务
                currDb.CommitTran();
                //返回执行结果
                return(result ? ResponseUtil <bool> .SuccessResult(true) : ResponseUtil <bool> .FailResult(false, "新增数据失败!"));
            }
            catch (Exception ex)
            {
                //回滚事务
                currDb.RollbackTran();
                //返回异常结果
                return(ResponseUtil <bool> .FailResult(false, ex.Message));
            }
        }
Пример #17
0
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="requestObject"></param>
        /// <returns></returns>
        public async Task <ResponseObject <TPMUserAccountAddModel, LoginResult> > LoginAsync(RequestObject <TPMUserAccountAddModel> requestObject)
        {
            LoginResult loginResult = new LoginResult()
            {
                IsSuccess = false
            };

            try
            {
                //当前登录账户信息
                var curr = requestObject.PostData;

                if (string.IsNullOrWhiteSpace(curr.LoginName))
                {
                    return(ResponseUtil <TPMUserAccountAddModel, LoginResult> .FailResult(requestObject, loginResult, "登录失败,账户不能为空!"));
                }

                //查询数据库是否有该账户
                var dbModel = await _db.Instance.Queryable <TUsersModel>()
                              .Where(p => p.LoginName == curr.LoginName && p.Status == true)
                              .FirstAsync();

                //如果没有该账户返回错误信息
                if (dbModel == null)
                {
                    return(ResponseUtil <TPMUserAccountAddModel, LoginResult> .FailResult(requestObject, loginResult, "登录失败,账户不存在!"));
                }
                //验证密码
                var currPwd = EncryptUtil.DeAESbyKey(dbModel.LoginPwd, Encoding.UTF8, dbModel.Salt);
                if (string.Equals(curr.Passwd, currPwd))
                {
                    loginResult.IsSuccess = true;

                    //生成Token
                    Dictionary <string, object> palyloads = new Dictionary <string, object>();
                    palyloads.Add("UserID", dbModel.Id);
                    string token = TokenManager.CreateTokenByHandler(palyloads, 60);

                    loginResult.Token = token;

                    //加载权限
                    //RequestObject<TRolePermissionsModel> roleQuery = new RequestObject<TRolePermissionsModel>() { IsPaging = false, QueryConditions = new List<QueryCondition>() };
                    //roleQuery.QueryConditions.Add(new QueryCondition() { Column = "roleID", Content = dbModel.RoleId.ToString(), Condition = ConditionEnum.Equal });
                    //var result = await _rolePermissionsService.LoadMenuByRoles(roleQuery);

                    //loginResult.Permissions = result.Data;

                    //返回验证成功信息
                    return(ResponseUtil <TPMUserAccountAddModel, LoginResult> .SuccessResult(requestObject, loginResult));
                }
                else
                {
                    //返回密码验证失败的错误信息
                    return(ResponseUtil <TPMUserAccountAddModel, LoginResult> .FailResult(requestObject, loginResult, "登录失败,密码错误"));
                }
            }
            catch (Exception ex)
            {
                //返回异常信息
                return(ResponseUtil <TPMUserAccountAddModel, LoginResult> .FailResult(requestObject, loginResult, $"登录失败,发生异常,{Environment.NewLine}{ex.Message}"));
            }
        }
        /// <summary>
        /// 修改T_MM_ColorSolutionMain数据
        /// </summary>
        /// <param name="requestObject">Put请求参数</param>
        /// <param name="currentUser"></param>
        /// <returns>返回响应结果对象,包括响应代码,修改操作结果</returns>
        public async Task <ResponseObject <bool> > PutAsync(RequestPut <TMMColorSolutionMainEditNewModel> requestObject, CurrentUser currentUser)
        {
            var currDb = _db.Instance;//事务需要使用同一个 SqlSugarClient对象实例

            try
            {
                if (requestObject.PostData == null)
                {
                    return(ResponseUtil <bool> .FailResult(false, "PostData不能为null"));
                }
                if (requestObject.PostData.ChildList == null || requestObject.PostData.ChildList.Count < 1)
                {
                    return(ResponseUtil <bool> .FailResult(false, "PostData.ChildList至少包含一条数据"));
                }
                //开启事务
                currDb.BeginTran();
                //修改主表信息
                var mainModel = _mapper.Map <TMMColorSolutionMainDbModel>(requestObject.PostData);
                if (_db.Instance.Queryable <TMMColorSolutionMainDbModel>().Any(p => p.SolutionCode == mainModel.SolutionCode && p.PackageId == mainModel.PackageId &&
                                                                               p.CompanyId == currentUser.CompanyID && p.ID != mainModel.ID && p.DeleteFlag == false))
                {
                    throw new Exception("编号重复");
                }
                var mainFlag = await currDb.Updateable(mainModel).IgnoreColumns(p => new { p.CompanyId }).ExecuteCommandAsync() > 0;

                /*
                 * 修改明细逻辑
                 * 1.根据主单ID查询现有明细数据
                 * 2.PostData.ChildList中明细ID <= 0的新增
                 * 3.PostData.ChildList中明细ID > 0的修改
                 * 4.删除不在PostData.CihldList中的数据
                 */
                var detailFlag   = true;
                var detailModels = _mapper.Map <List <TMMColorSolutionDetailEditNewModel>,
                                                List <TMMColorSolutionDetailDbModel> >(requestObject.PostData.ChildList);
                foreach (var item in detailModels)
                {
                    if (!detailFlag)
                    {
                        break;
                    }
                    item.MainId = mainModel.ID;
                    //新增或修改明细数据
                    detailFlag = item.ID <= 0
                        ? await currDb.Insertable(item).ExecuteCommandIdentityIntoEntityAsync()
                        : await currDb.Updateable(item).ExecuteCommandAsync() > 0;
                }

                //删除明细数据
                var detailIds = detailModels.Select(p => p.ID).ToList();
                detailFlag = currDb.Deleteable <TMMColorSolutionDetailDbModel>()
                             .Where(p => !detailIds.Contains(p.ID) && p.MainId == mainModel.ID)
                             .ExecuteCommand() >= 0;

                //提交事务
                currDb.CommitTran();
                //返回执行结果
                return(ResponseUtil <bool> .SuccessResult(true));
            }
            catch (Exception ex)
            {
                //回滚事务
                currDb.RollbackTran();
                //返回异常结果
                return(ResponseUtil <bool> .FailResult(false, ex.Message));
            }
        }
Пример #19
0
        /// <summary>
        /// 修改T_SSM_SalesOrderMain数据
        /// </summary>
        /// <param name="requestObject">Put请求参数</param>
        /// <returns>返回响应结果对象,包括响应代码,修改操作结果</returns>
        public async Task <ResponseObject <bool> > PutAsync(RequestPut <TSSMSalesOrderMainEditNPModel> requestObject, CurrentUser currentUser)
        {
            var currDb = _db.Instance;//事务需要使用同一个 SqlSugarClient对象实例

            try
            {
                if (requestObject.PostData == null)
                {
                    return(ResponseUtil <bool> .FailResult(false, "PostData不能为null"));
                }
                if (requestObject.PostData.ChildList == null || requestObject.PostData.ChildList.Count < 1)
                {
                    return(ResponseUtil <bool> .FailResult(false, "PostData.ChildList至少包含一条数据"));
                }
                //开启事务
                currDb.BeginTran();
                //修改主表信息
                var mainModel = _mapper.Map <TSSMSalesOrderMainDbModel>(requestObject.PostData);
                mainModel.SalesNum    = requestObject.PostData.ChildList.Sum(p => p.SalesNum);
                mainModel.SalesAmount = requestObject.PostData.ChildList.Sum(p => p.SalesAmount);
                var mainFlag = await currDb.Updateable(mainModel)
                               .UpdateColumns(p => new
                {
                    p.CustomerId,
                    p.SalesmanId,
                    p.OrderTypeId,
                    p.SettlementTypeId,
                    p.ReceiptAddress,
                    p.OrderDate,
                    p.ContactName,
                    p.ContactNumber,
                    p.SalesAmount,
                    p.SalesNum
                })
                               .Where(p => (SqlFunc.IsNullOrEmpty(p.AuditStatus) || p.AuditStatus != 2) && p.ID == mainModel.ID)
                               .ExecuteCommandAsync() > 0;

                /*
                 * 修改明细逻辑
                 * 1.根据主单ID查询现有明细数据
                 * 2.PostData.ChildList中明细ID <= 0的新增
                 * 3.PostData.ChildList中明细ID > 0的修改
                 * 4.删除不在PostData.CihldList中的数据
                 */
                var detailFlag   = true;
                var detailModels = _mapper.Map <List <TSSMSalesOrderDetailEditNPModel>,
                                                List <TSSMSalesOrderDetailDbModel> >(requestObject.PostData.ChildList);

                foreach (var item in detailModels)
                {
                    if (!detailFlag)
                    {
                        break;
                    }
                    item.MainId = mainModel.ID;
                    //新增或修改明细数据
                    detailFlag = item.ID <= 0
                        ? await currDb.Insertable(item).ExecuteCommandIdentityIntoEntityAsync()
                        : await currDb.Updateable(item).ExecuteCommandAsync() > 0;
                }

                //删除明细数据
                if (detailFlag)
                {
                    var detailIds = detailModels.Select(p => p.ID).ToList();
                    detailFlag = currDb.Deleteable <TSSMSalesOrderDetailDbModel>()
                                 .Where(p => !detailIds.Contains(p.ID) && p.MainId == mainModel.ID)
                                 .ExecuteCommand() >= 0;
                }

                //提交事务
                currDb.CommitTran();
                //返回执行结果
                return(mainFlag && detailFlag ? ResponseUtil <bool> .SuccessResult(true) : ResponseUtil <bool> .FailResult(false, "修改数据失败!"));
            }
            catch (Exception ex)
            {
                //回滚事务
                currDb.RollbackTran();
                //返回异常结果
                return(ResponseUtil <bool> .FailResult(false, ex.Message));
            }
        }
        /// <summary>
        /// 获取T_MM_ColorSolutionMain主表数据数据
        /// </summary>
        /// <param name="requestObject">Get请求参数</param>
        /// <returns>返回响应结果对象,包括响应代码,查询操作结果</returns>
        public async Task <ResponseObject <DataTable> > GetAsync(RequestGet requestObject, CurrentUser currentUser)
        {
            try
            {
                List <TMMColorSolutionMainQueryNewModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber = -1;                           //总记录数
                var            query       = _db.Instance.Queryable <TMMColorSolutionMainDbModel, TBMDictionaryDbModel>(
                    (t1, t2) => new object[]
                {
                    JoinType.Left, t1.ColorId == t2.ID,
                }
                    ).Where(t1 => t1.CompanyId == currentUser.CompanyID && t1.DeleteFlag == false);

                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var conditionals = SqlSugarUtil.GetConditionalModels(requestObject.QueryConditions);
                    query.Where(conditionals);
                }

                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TMMColorSolutionMainDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query.Where(t1 => !t1.DeleteFlag)
                                .Select((t1, t2) => new TMMColorSolutionMainQueryNewModel
                    {
                        ID           = t1.ID,
                        PackageId    = t1.PackageId,
                        SolutionCode = t1.SolutionCode,
                        ImagePath    = t1.ImagePath,
                        ColorId      = t1.ColorId,
                        ColorName    = t2.DicValue
                    })
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query.Where(t1 => !t1.DeleteFlag)
                                .Select((t1, t2) => new TMMColorSolutionMainQueryNewModel
                    {
                        ID           = t1.ID,
                        PackageId    = t1.PackageId,
                        SolutionCode = t1.SolutionCode,
                        ImagePath    = t1.ImagePath,
                        ColorId      = t1.ColorId,
                        ColorName    = t2.DicValue
                    })
                                .ToListAsync();
                }

                List <TMMColorSolutionDetailQueryNewModel> detailList = null;
                if (queryData != null && queryData.Count > 0)
                {
                    detailList = await _db.Instance.Queryable <TMMColorSolutionDetailDbModel, TMMPackageColorItemDbModel, TBMDictionaryDbModel>(
                        (t, t0, t1) => new object[]
                    {
                        JoinType.Left, t.ItemId == t0.ID,
                        JoinType.Left, t.ColorId == t1.ID
                    }
                        )
                                 .In(t => t.MainId, queryData.Select(p => p.ID).ToArray())
                                 .Select((t, t0, t1) => new TMMColorSolutionDetailQueryNewModel
                    {
                        ID        = t.ID,
                        MainId    = t.MainId,
                        ItemId    = t.ItemId,
                        ItemName  = t0.ItemName,
                        ColorId   = t.ColorId,
                        ColorName = t1.DicValue
                    })
                                 .ToListAsync();
                }
                var returnTable = GetReturnDataTable(queryData, detailList);
                //返回执行结果
                return(ResponseUtil <DataTable> .SuccessResult(returnTable, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <DataTable> .FailResult(null, ex.Message));
            }
        }
Пример #21
0
        /// <summary>
        /// 查询日志
        /// </summary>
        /// <param name="requestObject"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public ResponseObject <LogQueryModel, List <OperateLog> > Get(RequestObject <LogQueryModel> requestObject, int UserId)
        {
            try
            {
                long       totalNum   = -1;
                SMUserInfo sMUserInfo = SMCurentUserManager.GetCurentUserID(UserId, _db.Instance);

                List <OperateLog> result = new List <OperateLog>();

                Expression <Func <OperateLog, bool> > pression = p => p.CompanyID == sMUserInfo.CompanyId.Value;

                var queryEntiy = requestObject.PostData;
                if (queryEntiy != null)
                {
                    if (!string.IsNullOrEmpty(queryEntiy.Account))
                    {
                        pression = pression.And(p => p.Account.Contains(queryEntiy.Account));
                    }
                    if (!string.IsNullOrEmpty(queryEntiy.Path))
                    {
                        pression = pression.And(p => p.Path.Contains(queryEntiy.Path));
                    }

                    if (!string.IsNullOrEmpty(queryEntiy.RealName))
                    {
                        pression = pression.And(p => p.RealName.Contains(queryEntiy.RealName));
                    }

                    if (!string.IsNullOrEmpty(queryEntiy.IpAddress))
                    {
                        pression = pression.And(p => p.IpAddress == queryEntiy.IpAddress);
                    }

                    if (queryEntiy.CreateTimeBg != null)
                    {
                        pression = pression.And(p => p.CreateTime >= queryEntiy.CreateTimeBg.Value);
                    }

                    if (queryEntiy.CreateTimeEd != null)
                    {
                        DateTime eg = queryEntiy.CreateTimeEd.Value.AddDays(1);
                        pression = pression.And(p => p.CreateTime < eg);
                    }
                }
                var sort = Builders <OperateLog> .Sort.Descending(y => y.CreateTime);

                if (requestObject.IsPaging == true)
                {
                    result = MongoDbUtil.GetDoc <OperateLog>(pression, requestObject.PageIndex, requestObject.PageSize, sort, ref totalNum);
                }
                else
                {
                    result = MongoDbUtil.GetDoc <OperateLog>(pression, sort).ToList();
                }


                return(ResponseUtil <LogQueryModel, List <OperateLog> > .SuccessResult(requestObject, result, totalNum));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <LogQueryModel, List <OperateLog> > .FailResult(requestObject, null, ex.Message));
            }
        }
Пример #22
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="requestObject"></param>
        /// <param name="UserID">操作人ID</param>
        /// <returns></returns>
        public async Task <ResponseObject <TSMUserAccountQueryAllModel, List <TSMUserAccountQueryAllModel> > > GetAsync(RequestObject <TSMUserAccountQueryAllModel> requestObject, int UserID)
        {
            try
            {
                List <TSMUserAccountQueryAllModel> queryData = null;//查询结果集对象
                var user = _db.Instance.Queryable <TSMUserAccountDbModel, TSMCompanyDbModel>(
                    (t, t1) => new object[]
                {
                    JoinType.Left, t.CompanyId == t1.ID,
                }).Where((t, t1) => t.ID == UserID).Select((t, t1) => new { CompanyId = t.CompanyId, Name = t1.CompanyName }).First();

                if (user.CompanyId == null)
                {
                    return(ResponseUtil <TSMUserAccountQueryAllModel, List <TSMUserAccountQueryAllModel> > .FailResult(requestObject, null, "当前用户没有公司"));
                }

                RefAsync <int> totalNumber = -1;//总记录数
                var            query       = _db.Instance.Queryable <TSMUserAccountDbModel, TSMUserInfoDbModel, TSMRoleUserRelationDbModel, TSMRolesDbModel, TSMDeptUserRelationDbModel, TSMDeptDbModel>(
                    (t, t1, t2, t2_1, t3, t3_1) => new object[]
                {
                    JoinType.Left, t.UserInfoId == t1.ID,
                    JoinType.Left, t.ID == t2.UserId,
                    JoinType.Left, t2.RoleId == t2_1.Id,
                    JoinType.Left, t.ID == t3.UserAccountId,
                    JoinType.Left, t3.DeptId == t3_1.Id
                }).Where(t => t.CompanyId == user.CompanyId);


                string[] cQuery = { "jobnumber", "realname", "fixednumber", "address", "headpicpath", "remarks", "account" };



                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var itemCondition = requestObject.QueryConditions.Where(p => p.Column.ToLower() == "keywords").FirstOrDefault();

                    if (itemCondition != null && !string.IsNullOrEmpty(itemCondition.Content))
                    {
                        query = query.Where((t, t1) => t.TelAccount.Contains(itemCondition.Content) || t.EmailAccount.Contains(itemCondition.Content));
                    }

                    requestObject.QueryConditions.Remove(itemCondition);

                    var QueryConditions1 = requestObject.QueryConditions.Where(p => !cQuery.Contains(p.Column.ToLower())).ToList();

                    var conditionals1 = SqlSugarUtil.GetConditionalModels(QueryConditions1);

                    foreach (ConditionalModel item in conditionals1)
                    {
                        item.FieldName = $"t.{item.FieldName}";
                    }
                    query.Where(conditionals1);


                    var QueryConditions2 = requestObject.QueryConditions.Where(p => cQuery.Contains(p.Column.ToLower())).ToList();
                    var conditionals2    = SqlSugarUtil.GetConditionalModels(QueryConditions2);
                    query.Where(conditionals2);
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions.Where(p => !cQuery.Contains(p.Column.ToLower())))
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TSMUserInfoDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"t {item.Column} {item.Condition}");
                    }

                    foreach (var item in requestObject.OrderByConditions.Where(p => cQuery.Contains(p.Column.ToLower())))
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TSMUserInfoDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"t1 {item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query.Select(
                        (t, t1, t2, t2_1, t3, t3_1) => new TSMUserAccountQueryAllModel
                    {
                        ID           = t.ID,
                        TelAccount   = t.TelAccount,
                        EmailAccount = t.EmailAccount,
                        Passwd       = t.Passwd,
                        Salt         = t.Salt,
                        AccountName  = t.AccountName,
                        UserInfoId   = t.UserInfoId,
                        CompanyId    = t.CompanyId,
                        Status       = t.Status,
                        ExpDate      = t.ExpDate,
                        CreateTime   = t.CreateTime,

                        RoleId                 = t2.RoleId,
                        RoleName               = t2_1.RoleName,
                        DeptId                 = t3.DeptId,
                        DeptName               = t3_1.DeptName,
                        CId                    = t1.ID,
                        JobNumber              = t1.JobNumber,
                        RealName               = t1.RealName,
                        FixedNumber            = t1.FixedNumber,
                        Address                = t1.Address,
                        HeadPicPath            = t1.HeadPicPath,
                        Sex                    = t1.Sex,
                        EntryTime              = t1.EntryTime,
                        WorkNo                 = t1.WorkNo,
                        WorkStatus             = t1.WorkStatus,
                        IDCard                 = t1.IDCard,
                        Birthday               = t1.Birthday,
                        Education              = t1.Education,
                        Nation                 = t1.Nation,
                        Marriage               = t1.Marriage,
                        RegisteredType         = t1.RegisteredType,
                        HomeAddress            = t1.HomeAddress,
                        EmergencyContact       = t1.EmergencyContact,
                        EmergencyContactaPhone = t1.EmergencyContactaPhone,
                        EmergencyRealtionShip  = t1.EmergencyRealtionShip,
                        Remarks                = t1.Remarks,
                    })
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query.Select(
                        (t, t1, t2, t2_1, t3, t3_1) => new TSMUserAccountQueryAllModel
                    {
                        ID           = t.ID,
                        TelAccount   = t.TelAccount,
                        EmailAccount = t.EmailAccount,
                        Passwd       = t.Passwd,
                        Salt         = t.Salt,
                        AccountName  = t.AccountName,
                        UserInfoId   = t.UserInfoId,
                        CompanyId    = t.CompanyId,
                        Status       = t.Status,
                        ExpDate      = t.ExpDate,
                        CreateTime   = t.CreateTime,

                        RoleId                 = t2.RoleId,
                        RoleName               = t2_1.RoleName,
                        DeptId                 = t3.DeptId,
                        DeptName               = t3_1.DeptName,
                        CId                    = t1.ID,
                        JobNumber              = t1.JobNumber,
                        RealName               = t1.RealName,
                        FixedNumber            = t1.FixedNumber,
                        Address                = t1.Address,
                        HeadPicPath            = t1.HeadPicPath,
                        Sex                    = t1.Sex,
                        EntryTime              = t1.EntryTime,
                        WorkNo                 = t1.WorkNo,
                        WorkStatus             = t1.WorkStatus,
                        IDCard                 = t1.IDCard,
                        Birthday               = t1.Birthday,
                        Education              = t1.Education,
                        Nation                 = t1.Nation,
                        Marriage               = t1.Marriage,
                        RegisteredType         = t1.RegisteredType,
                        HomeAddress            = t1.HomeAddress,
                        EmergencyContact       = t1.EmergencyContact,
                        EmergencyContactaPhone = t1.EmergencyContactaPhone,
                        EmergencyRealtionShip  = t1.EmergencyRealtionShip,
                        Remarks                = t1.Remarks,
                    })
                                .ToListAsync();
                }

                queryData.ForEach((x =>
                {
                    if (x.Birthday != null)
                    {
                        x.Age = DateTime.Now.Year - x.Birthday.Value.Year;
                    }
                    if (x.EntryTime != null)
                    {
                        x.EntryAge = DateTime.Now.Year - x.EntryTime.Value.Year;
                    }

                    x.Passwd = EncryptUtil.DeAESbyKey(x.Passwd, x.Salt);
                    x.Salt = null;
                }));

                //返回执行结果
                return(ResponseUtil <TSMUserAccountQueryAllModel, List <TSMUserAccountQueryAllModel> > .SuccessResult(requestObject, queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <TSMUserAccountQueryAllModel, List <TSMUserAccountQueryAllModel> > .FailResult(requestObject, null, ex.Message));
            }
        }
        /// <summary>
        /// 生产入库态势(周)
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <ProductionWarehousingModel> > GetProductionWarehousingWeek(CurrentUser currentUser)
        {
            try
            {
                DateTime _thisDateTime = DateTime.Now;
                int      y             = Convert.ToInt32(_thisDateTime.ToString("yyyy"));
                int      m             = Convert.ToInt32(_thisDateTime.ToString("MM"));
                //获取本月的天数
                var      date_count = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                DateTime firstDay   = _thisDateTime.AddDays(1 - _thisDateTime.Day);
                int      weekday    = (int)firstDay.DayOfWeek == 0 ? 7 : (int)firstDay.DayOfWeek;
                //本月第一周有几天
                int firstWeekEndDay = 7 - (weekday - 1);
                var days            = date_count;
                var mod             = firstWeekEndDay; //本月第一周有几天
                var count           = 1;
                var start           = 1;               //起始日期 1 号开始
                var s1  = "";
                var s2  = "";
                var ss1 = "";
                var ss2 = "";
                var end = start + mod - 1;//截止日期
                while (days >= 0)
                {
                    //var end = start + 6;
                    end  = end > date_count ? date_count : end;
                    ss1 += "第" + count + "周:" + y + "年" + m + "月" + "(" + start + "-" + end + ");" + "\n";
                    s1  += ",第" + count + "周";
                    DateTime dt1 = Convert.ToDateTime("" + y + "-" + m + "-" + start);

                    DateTime dt2;
                    if ((end + 1) > date_count)
                    {
                        dt2 = Convert.ToDateTime("" + y + "-" + (m + 1) + "-01");
                    }
                    else
                    {
                        dt2 = Convert.ToDateTime("" + y + "-" + m + "-" + (end + 1));
                    }

                    var today = await _db.Instance.Queryable <TWMProductionWhMainDbModel>()
                                .Where(t => t.CompanyId == currentUser.CompanyID && t.AuditStatus == 2 && t.DeleteFlag == false &&
                                       t.WarehousingDate >= dt1 && t.WarehousingDate < dt2
                                       ).Select(t => SqlFunc.AggregateSum(t.Number)).ToListAsync();

                    if (today.Count > 0)
                    {
                        s2 += "|" + String.Format("{0:N2}", today[0]);
                    }
                    else
                    {
                        s2 += "|0.00";
                    }
                    start = end + 1;
                    end  += 7;
                    days -= 7;
                    ss2  += days + ",";
                    count++;
                }
                ProductionWarehousingModel _model = new ProductionWarehousingModel {
                    xAxisData = s1.Substring(1).Split(','), SeriesData = s2.Substring(1).Split('|')
                };
                return(ResponseUtil <ProductionWarehousingModel> .SuccessResult(_model));
            }
            catch (Exception ex)
            {
                return(ResponseUtil <ProductionWarehousingModel>
                       .FailResult(null, $"生产入库态势(周) 发生异常{System.Environment.NewLine} {ex.Message}"));
            }
        }
Пример #24
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="requestObject"></param>
        /// <param name="UserID">操作人ID</param>
        /// <returns></returns>
        public async Task <ResponseObject <TSMUserAccountAddAllModel, bool> > PostAsync(RequestObject <TSMUserAccountAddAllModel> requestObject, int UserID)
        {
            var currDb = _db.Instance;//事务需要使用同一个 SqlSugarClient对象实例

            try
            {
                //没有新增数据,返回错误信息
                if (requestObject.PostData == null)
                {
                    return(ResponseUtil <TSMUserAccountAddAllModel, bool> .FailResult(requestObject, false, "PostData不能为null"));
                }
                //开启事务
                currDb.BeginTran();

                var user = _db.Instance.Queryable <TSMUserAccountDbModel, TSMCompanyDbModel>(
                    (t, t1) => new object[]
                {
                    JoinType.Left, t.CompanyId == t1.ID,
                }).Where((t, t1) => t.ID == UserID).Select((t, t1) => new { CompanyId = t.CompanyId, Name = t1.CompanyName }).First();


                TSMUserAccountDbModel dbMain = ExpressionGenericMapper <TSMUserAccountAddAllModel, TSMUserAccountDbModel> .Trans(requestObject.PostData);

                //处理密码
                dbMain.Salt       = RandCodeCreate.GenerateRandomNumber(32);
                dbMain.Passwd     = EncryptUtil.EnAESBykey(dbMain.Passwd, dbMain.Salt);
                dbMain.CreateTime = DateTime.Now;
                dbMain.CompanyId  = user.CompanyId.Value;

                if (string.IsNullOrWhiteSpace(dbMain.EmailAccount))
                {
                    dbMain.EmailAccount = null;
                }

                if (string.IsNullOrWhiteSpace(dbMain.TelAccount))
                {
                    dbMain.TelAccount = null;
                }

                TSMUserInfoDbModel dbDeatail = ExpressionGenericMapper <TSMUserAccountAddAllModel, TSMUserInfoDbModel> .Trans(requestObject.PostData);

                //插入主表数据
                var cId = await currDb.Insertable(dbDeatail).ExecuteReturnIdentityAsync();

                dbMain.UserInfoId = cId;
                //插入从表数据
                var mId = await currDb.Insertable(dbMain).ExecuteReturnIdentityAsync();

                if (requestObject.PostData.RoleId != null && requestObject.PostData.RoleId > 0)
                {
                    TSMRoleUserRelationDbModel itemEntity = new TSMRoleUserRelationDbModel();
                    itemEntity.RoleId = requestObject.PostData.RoleId.Value;
                    itemEntity.UserId = mId;

                    currDb.Insertable <TSMRoleUserRelationDbModel>(itemEntity).ExecuteCommand();
                }

                if (requestObject.PostData.DeptId != null && requestObject.PostData.DeptId > 0)
                {
                    TSMDeptUserRelationDbModel itemEntity = new TSMDeptUserRelationDbModel();
                    itemEntity.DeptId        = requestObject.PostData.DeptId.Value;
                    itemEntity.UserAccountId = mId;
                    currDb.Insertable <TSMDeptUserRelationDbModel>(itemEntity).ExecuteCommand();
                }



                //提交事务
                currDb.CommitTran();
                //返回执行结果

                return(ResponseUtil <TSMUserAccountAddAllModel, bool> .SuccessResult(requestObject, true));
            }
            catch (Exception ex)
            {
                //回滚事务
                currDb.RollbackTran();
                //返回异常结果
                return(ResponseUtil <TSMUserAccountAddAllModel, bool> .FailResult(requestObject, false, ex.Message));
            }
        }
        /// <summary>
        /// 生产一览表
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <ProductionOrderListModel> > GetProdutionCountList(RequestGet request, CurrentUser currentUser)
        {
            try
            {
                List <ProductionOrderCountListModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber = -1;                       //总记录数
                var            query       = _db.Instance.Queryable <TMMProductionOrderDetailDbModel, TMMProductionOrderMainDbModel
                                                                     , TBMDictionaryDbModel, TBMDictionaryDbModel, TBMCustomerFileDbModel, TBMPackageDbModel>(
                    (t1, t2, t3, t4, t5, t6) => new object[]
                {
                    JoinType.Left, t1.MainId == t2.ID,
                    JoinType.Left, t2.ProductionType == t3.ID,
                    JoinType.Left, t1.WorkshopId == t4.ID,
                    JoinType.Left, t2.CustomerId == t5.ID,
                    JoinType.Left, t1.PackageId == t6.ID
                }
                    ).Where((t1, t2, t3, t4, t5, t6) => t2.CompanyId == currentUser.CompanyID)
                                             .OrderBy((t1, t2, t3, t4, t5, t6) => t2.ID, OrderByType.Desc);
                //查询条件
                if (request.QueryConditions != null && request.QueryConditions.Count > 0)
                {
                    var conditionals = SqlSugarUtil.GetConditionalModels(request.QueryConditions);

                    foreach (ConditionalModel item in conditionals)
                    {
                        if (item.FieldName.ToLower() == "orderdate" || item.FieldName.ToLower() == "customerid" || item.FieldName.ToLower() == "productionno" || item.FieldName.ToLower() == "productiontype")
                        {
                            item.FieldName = $"t2.{item.FieldName}";
                            continue;
                        }
                        if (item.FieldName.ToLower() == "packageid" || item.FieldName.ToLower() == "workshopid")
                        {
                            item.FieldName = $"t1.{item.FieldName}";
                            continue;
                        }
                    }
                    query.Where(conditionals);
                }
                //排序条件
                if (request.OrderByConditions != null && request.OrderByConditions.Count > 0)
                {
                    foreach (var item in request.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TBMDictionaryDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"t2.{item.Column} {item.Condition}");
                    }
                }


                var today = _db.Instance.Queryable <TWMProductionWhDetailDbModel, TWMProductionWhMainDbModel
                                                    , TMMWhApplyDetailDbModel>(
                    (t1, t2, t3) => new object[] {
                    JoinType.Left, t1.MainId == t2.ID,
                    JoinType.Left, t1.ProOrderDetailId == t3.ID
                }
                    )
                            .Where((t1, t2, t3) => t2.CompanyId == currentUser.CompanyID && t2.AuditStatus == 2 && t2.DeleteFlag == false &&
                                   t2.WarehousingDate >= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) &&
                                   t2.WarehousingDate < Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")))
                            .GroupBy((t1, t2, t3) => t3.ProOrderDetailId)
                            .Select((t1, t2, t3) => new { ProOrderDetailId = t3.ProOrderDetailId, ToDayNum = SqlFunc.AggregateSum(t1.ActualNum) })
                            .ToList().ToDictionary(p => p.ProOrderDetailId, p => p.ToDayNum);

                var Total = _db.Instance.Queryable <TWMProductionWhDetailDbModel, TWMProductionWhMainDbModel
                                                    , TMMWhApplyDetailDbModel>(
                    (t1, t2, t3) => new object[] {
                    JoinType.Left, t1.MainId == t2.ID,
                    JoinType.Left, t1.ProOrderDetailId == t3.ID
                }
                    )
                            .Where((t1, t2, t3) => t2.CompanyId == currentUser.CompanyID && t2.AuditStatus == 2 && t2.DeleteFlag == false)
                            .GroupBy((t1, t2, t3) => t3.ProOrderDetailId)
                            .Select((t1, t2, t3) => new { ProOrderDetailId = t3.ProOrderDetailId, ToDayNum = SqlFunc.AggregateSum(t1.ActualNum) })
                            .ToList().ToDictionary(p => p.ProOrderDetailId, p => p.ToDayNum);

                ProductionOrderListModel _list = new ProductionOrderListModel();
                _list.Total_Number = query.Count();
                #region 统计生产数量
                var PurchaseNum = query.Select((t1, t2, t3, t4, t5, t6) => SqlFunc.AggregateSum(t1.ProductionNum)).ToList();
                _list.Total_Num = PurchaseNum.Count > 0 ? Convert.ToDecimal(PurchaseNum.ToList()[0]) : 0;
                #endregion
                if (request.IsPaging)
                {
                    int skipNum = request.PageSize * (request.PageIndex - 1);
                    queryData = await query
                                .Select((t1, t2, t3, t4, t5, t6) => new ProductionOrderCountListModel
                    {
                        ID               = t2.ID,
                        ProductionNo     = t2.ProductionNo,
                        DetailID         = t1.ID,
                        PackageName      = t6.DicValue,
                        CustomerName     = t5.CustomerName,
                        ProductionTypeId = t2.ProductionType,
                        ProductionNum    = t1.ProductionNum,
                        WorkshopName     = t4.DicValue,
                        ToDayNum         = 0,
                        TotalNum         = 0,
                        OrderDate        = t2.OrderDate
                    }).Skip(skipNum).Take(request.PageSize).ToListAsync();
                }
                else
                {
                    queryData = await query
                                .Select((t1, t2, t3, t4, t5, t6) => new ProductionOrderCountListModel
                    {
                        ID               = t2.ID,
                        ProductionNo     = t2.ProductionNo,
                        DetailID         = t1.ID,
                        PackageName      = t6.DicValue,
                        CustomerName     = t5.CustomerName,
                        ProductionTypeId = t2.ProductionType,
                        ProductionNum    = t1.ProductionNum,
                        WorkshopName     = t4.DicValue,
                        ToDayNum         = 0,
                        TotalNum         = 0,
                        OrderDate        = t2.OrderDate
                    })
                                .ToListAsync();
                }

                queryData.ForEach(x =>
                {
                    if (today.ContainsKey(x.DetailID))
                    {
                        x.ToDayNum          = today[x.DetailID];
                        _list.Total_DayNum += x.ToDayNum;
                    }
                    if (Total.ContainsKey(x.DetailID))
                    {
                        x.TotalNum            = Total[x.DetailID];
                        _list.Total_TotalNum += x.TotalNum;
                    }
                });
                _list.List = queryData;
                return(ResponseUtil <ProductionOrderListModel> .SuccessResult(_list));
            }
            catch (Exception ex)
            {
                return(ResponseUtil <ProductionOrderListModel>
                       .FailResult(null, $"生产一览表发生异常{System.Environment.NewLine} {ex.Message}"));
            }
        }
Пример #26
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="requestObject"></param>
        /// <param name="UserID">操作人ID</param>
        /// <returns></returns>
        public async Task <ResponseObject <TUserDeatail, List <TUserDeatail> > > GetUserInCurentCompany(RequestObject <TUserDeatail> requestObject, int UserID)
        {
            try
            {
                List <TUserDeatail> queryData = null;//查询结果集对象
                var user = _db.Instance.Queryable <TSMUserAccountDbModel, TSMCompanyDbModel>(
                    (t, t1) => new object[]
                {
                    JoinType.Left, t.CompanyId == t1.ID,
                }).Where((t, t1) => t.ID == UserID).Select((t, t1) => new { CompanyId = t.CompanyId, Name = t1.CompanyName }).First();

                if (user.CompanyId == null)
                {
                    return(ResponseUtil <TUserDeatail, List <TUserDeatail> > .FailResult(requestObject, null, "当前用户没有公司"));
                }

                RefAsync <int> totalNumber = -1;//总记录数
                var            query       = _db.Instance.Queryable <TSMUserAccountDbModel, TSMUserInfoDbModel, TSMRoleUserRelationDbModel, TSMRolesDbModel, TSMDeptUserRelationDbModel, TSMDeptDbModel>(
                    (t, t1, t2, t2_1, t3, t3_1) => new object[]
                {
                    JoinType.Left, t.UserInfoId == t1.ID,
                    JoinType.Left, t.ID == t2.UserId,
                    JoinType.Left, t2.RoleId == t2_1.Id,
                    JoinType.Left, t.ID == t3.UserAccountId,
                    JoinType.Left, t3.DeptId == t3_1.Id
                }).Where(t => t.CompanyId == user.CompanyId);

                string[] Mquery = { "id" };
                string[] cQuery = { "jobnumber", "realname", "fixednumber", "address", "headpicpath", "remarks", "account" };
                string[] cc     = { "deptname" };


                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var QueryConditions1 = requestObject.QueryConditions.Where(p => !cQuery.Contains(p.Column.ToLower()) && !cc.Contains(p.Column.ToLower())).ToList();

                    var conditionals1 = SqlSugarUtil.GetConditionalModels(QueryConditions1);

                    foreach (ConditionalModel item in conditionals1)
                    {
                        item.FieldName = $"t.{item.FieldName}";
                    }
                    query.Where(conditionals1);


                    var QueryConditions2 = requestObject.QueryConditions.Where(p => cQuery.Contains(p.Column.ToLower())).ToList();
                    var conditionals2    = SqlSugarUtil.GetConditionalModels(QueryConditions2);
                    foreach (ConditionalModel item in conditionals1)
                    {
                        item.FieldName = $"t1.{item.FieldName}";
                    }
                    query.Where(conditionals2);

                    var QueryConditions3 = requestObject.QueryConditions.Where(p => cc.Contains(p.Column.ToLower())).ToList();
                    var conditionals3    = SqlSugarUtil.GetConditionalModels(QueryConditions3);
                    foreach (ConditionalModel item in conditionals3)
                    {
                        item.FieldName = $"t3_1.{item.FieldName}";
                    }
                    query.Where(conditionals3);
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions.Where(p => !cQuery.Contains(p.Column.ToLower())))
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TSMUserInfoDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"t {item.Column} {item.Condition}");
                    }

                    foreach (var item in requestObject.OrderByConditions.Where(p => cQuery.Contains(p.Column.ToLower())))
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TSMUserInfoDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"t1 {item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query.Select(
                        (t, t1, t2, t2_1, t3, t3_1) => new TUserDeatail
                    {
                        ID                     = t.ID,
                        DepartName             = t3_1.DeptName,
                        JobNumber              = t1.JobNumber,
                        RealName               = t.AccountName,
                        FixedNumber            = t1.FixedNumber,
                        Address                = t1.Address,
                        HeadPicPath            = t1.HeadPicPath,
                        Sex                    = t1.Sex,
                        EntryTime              = t1.EntryTime,
                        WorkNo                 = t1.WorkNo,
                        WorkStatus             = t1.WorkStatus,
                        IDCard                 = t1.IDCard,
                        Birthday               = t1.Birthday,
                        Education              = t1.Education,
                        Nation                 = t1.Nation,
                        Marriage               = t1.Marriage,
                        RegisteredType         = t1.RegisteredType,
                        HomeAddress            = t1.HomeAddress,
                        EmergencyContact       = t1.EmergencyContact,
                        EmergencyContactaPhone = t1.EmergencyContactaPhone,
                        EmergencyRealtionShip  = t1.EmergencyRealtionShip,
                        Remarks                = t1.Remarks,
                    })
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query.Select(
                        (t, t1, t2, t2_1, t3, t3_1) => new TUserDeatail
                    {
                        ID                     = t.ID,
                        JobNumber              = t1.JobNumber,
                        RealName               = t.AccountName,
                        FixedNumber            = t1.FixedNumber,
                        Address                = t1.Address,
                        HeadPicPath            = t1.HeadPicPath,
                        Sex                    = t1.Sex,
                        EntryTime              = t1.EntryTime,
                        WorkNo                 = t1.WorkNo,
                        WorkStatus             = t1.WorkStatus,
                        IDCard                 = t1.IDCard,
                        Birthday               = t1.Birthday,
                        Education              = t1.Education,
                        Nation                 = t1.Nation,
                        Marriage               = t1.Marriage,
                        RegisteredType         = t1.RegisteredType,
                        HomeAddress            = t1.HomeAddress,
                        EmergencyContact       = t1.EmergencyContact,
                        EmergencyContactaPhone = t1.EmergencyContactaPhone,
                        EmergencyRealtionShip  = t1.EmergencyRealtionShip,
                        Remarks                = t1.Remarks,
                    })
                                .ToListAsync();
                }


                //返回执行结果
                return(ResponseUtil <TUserDeatail, List <TUserDeatail> > .SuccessResult(requestObject, queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <TUserDeatail, List <TUserDeatail> > .FailResult(requestObject, null, ex.Message));
            }
        }
        /// <summary>
        /// 新增或修改T_RolePermissions数据
        /// </summary>
        /// <param name="requestObject">返回响应结果对象,包括响应代码,新增操作结果</param>
        /// <returns></returns>
        public async Task <ResponseObject <TRolePermissionsModel, bool> > PostAsync(RequestObject <TRolePermissionsModel> requestObject)
        {
            var currDb = _db.Instance;

            try
            {
                //如果没有新增数据,返回错误信息
                if (requestObject.PostDataList == null || requestObject.PostDataList.Count < 1)
                {
                    return(ResponseUtil <TRolePermissionsModel, bool> .FailResult(requestObject, false, "PostDataList不能为null"));
                }
                var result = false;
                //获取当前租户所有已有权限,根据提交
                var permissions = currDb.Queryable <TRolePermissionsModel>()
                                  .Where(p => p.RoleId == requestObject.PostDataList[0].RoleId)
                                  .ToList();
                //新增或修改权限
                foreach (var item in requestObject.PostDataList)
                {
                    //新增或修改
                    var dbCurrItem = permissions.Where(p => p.RoleId == item.RoleId && p.MenuId == item.MenuId).FirstOrDefault();
                    if (dbCurrItem == null)
                    {
                        result = await currDb.Insertable(item).ExecuteCommandIdentityIntoEntityAsync();
                    }
                    else
                    {
                        result = await currDb.Updateable(item).UpdateColumns(p => p.ButtonIds)
                                 .Where(p => p.RoleId == item.RoleId && p.MenuId == item.MenuId)
                                 .ExecuteCommandAsync() > 0;

                        item.Id = dbCurrItem.Id;
                    }

                    if (!result)
                    {
                        break;
                    }
                }

                //删除不存在的权限
                if (result)
                {
                    //删除不存在的权限
                    var ids = requestObject.PostDataList.Select(p => p.Id).ToList();
                    result = await currDb.Deleteable <TRolePermissionsModel>()
                             .Where(p => !ids.Contains(p.Id) && p.RoleId == requestObject.PostDataList[0].RoleId)
                             .ExecuteCommandAsync() >= 0;
                }
                else
                {
                    currDb.RollbackTran();
                    return(ResponseUtil <TRolePermissionsModel, bool> .FailResult(requestObject, false, "保存权限信息失败!"));
                }

                //返回执行结果
                if (result)
                {
                    currDb.CommitTran();
                    return(ResponseUtil <TRolePermissionsModel, bool> .SuccessResult(requestObject, true));
                }

                currDb.RollbackTran();
                return(ResponseUtil <TRolePermissionsModel, bool> .FailResult(requestObject, false, "保存权限信息失败!"));
            }
            catch (Exception ex)
            {
                currDb.RollbackTran();
                //返回异常结果
                return(ResponseUtil <TRolePermissionsModel, bool> .FailResult(requestObject, false, ex.Message));
            }
        }
Пример #28
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="requestObject"></param>
        /// <returns></returns>
        public async Task <ResponseObject <TSMUserAccountEditAllModel, bool> > PutAsync(RequestObject <TSMUserAccountEditAllModel> requestObject)
        {
            var currDb = _db.Instance;//事务需要使用同一个 SqlSugarClient对象实例

            try
            {
                //没有新增数据,返回错误信息
                if (requestObject.PostData == null)
                {
                    return(ResponseUtil <TSMUserAccountEditAllModel, bool> .FailResult(requestObject, false, "PostData不能为null"));
                }
                //开启事务
                currDb.BeginTran();

                TSMUserAccountDbModel dbMain = ExpressionGenericMapper <TSMUserAccountEditAllModel, TSMUserAccountDbModel> .Trans(requestObject.PostData);

                dbMain.Salt   = RandCodeCreate.GenerateRandomNumber(32);
                dbMain.Passwd = EncryptUtil.EnAESBykey(dbMain.Passwd, dbMain.Salt);

                if (string.IsNullOrWhiteSpace(dbMain.EmailAccount))
                {
                    dbMain.EmailAccount = null;
                }

                if (string.IsNullOrWhiteSpace(dbMain.TelAccount))
                {
                    dbMain.TelAccount = null;
                }


                TSMUserInfoDbModel dbDeatail = ExpressionGenericMapper <TSMUserAccountEditAllModel, TSMUserInfoDbModel> .Trans(requestObject.PostData);

                dbDeatail.ID = requestObject.PostData.CId;

                await currDb.Updateable(dbMain).IgnoreColumns(p => new { p.CreateTime, p.CompanyId, p.UserInfoId }).ExecuteCommandAsync();


                await currDb.Updateable(dbDeatail).ExecuteCommandAsync();


                currDb.Deleteable <TSMRoleUserRelationDbModel>().Where(p => p.UserId == dbMain.ID).ExecuteCommand();
                if (requestObject.PostData.RoleId != null && requestObject.PostData.RoleId > 0)
                {
                    TSMRoleUserRelationDbModel itemEntity = new TSMRoleUserRelationDbModel();
                    itemEntity.RoleId = requestObject.PostData.RoleId.Value;
                    itemEntity.UserId = dbMain.ID;

                    currDb.Insertable <TSMRoleUserRelationDbModel>(itemEntity).ExecuteCommand();
                }

                currDb.Deleteable <TSMDeptUserRelationDbModel>().Where(p => p.UserAccountId == dbMain.ID).ExecuteCommand();
                if (requestObject.PostData.DeptId != null && requestObject.PostData.DeptId > 0)
                {
                    TSMDeptUserRelationDbModel itemEntity = new TSMDeptUserRelationDbModel();
                    itemEntity.DeptId        = requestObject.PostData.DeptId.Value;
                    itemEntity.UserAccountId = dbMain.ID;

                    currDb.Insertable <TSMDeptUserRelationDbModel>(itemEntity).ExecuteCommand();
                }


                //提交事务
                currDb.CommitTran();
                //返回执行结果

                return(ResponseUtil <TSMUserAccountEditAllModel, bool> .SuccessResult(requestObject, true));
            }
            catch (Exception ex)
            {
                //回滚事务
                currDb.RollbackTran();
                //返回异常结果
                return(ResponseUtil <TSMUserAccountEditAllModel, bool> .FailResult(requestObject, false, ex.Message));
            }
        }
Пример #29
0
        /// <summary>
        /// 获取T_BM_Package数据
        /// </summary>
        /// <param name="requestObject">返回响应结果对象,包括响应代码,查询操作结果</param>
        /// <returns></returns>
        public async Task <ResponseObject <List <TBMPackageQueryModel> > > GetAsync(RequestGet requestObject, CurrentUser currentUser)
        {
            try
            {
                List <TBMPackageQueryModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber            = -1;   //总记录数
                var            query = _db.Instance.Queryable <TBMPackageDbModel, TSMUserAccountDbModel, TSMUserAccountDbModel>(
                    (t, t1, t2) => new object[]
                {
                    JoinType.Left, t.CreateId == t1.ID,
                    JoinType.Left, t.UpdateId == t2.ID
                }).Where((t, t1, t2) => SqlFunc.IsNull(t.DeleteFlag, false) == false && t.CompanyId == currentUser.CompanyID);
                //查询条件
                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var conditionals = SqlSugarUtil.GetConditionalModels(requestObject.QueryConditions);
                    foreach (ConditionalModel item in conditionals)
                    {
                        item.FieldName = item.FieldName = $"t.{item.FieldName}";
                    }
                    query.Where(conditionals);
                }
                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TBMPackageDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"{item.Column} {item.Condition}");
                    }
                }

                //执行查询
                if (requestObject.IsPaging)
                {
                    queryData = await query
                                .Where(t => t.DeleteFlag == false)
                                .Select((t, t1, t2) => new TBMPackageQueryModel
                    {
                        ID         = t.ID,
                        DicCode    = t.DicCode,
                        DicValue   = t.DicValue,
                        Remark     = t.Remark,
                        CreateTime = t.CreateTime,
                        CreateId   = t.CreateId,
                        CreateName = t1.AccountName,
                        UpdateTime = t.UpdateTime,
                        UpdateId   = t.UpdateId,
                        UpdateName = t2.AccountName,
                        ImgPath    = t.ImgPath,
                    })
                                .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber);
                }
                else
                {
                    queryData = await query
                                .Where(t => t.DeleteFlag == false)
                                .Select((t, t1, t2) => new TBMPackageQueryModel
                    {
                        ID         = t.ID,
                        DicCode    = t.DicCode,
                        DicValue   = t.DicValue,
                        Remark     = t.Remark,
                        CreateTime = t.CreateTime,
                        CreateId   = t.CreateId,
                        CreateName = t1.AccountName,
                        UpdateTime = t.UpdateTime,
                        UpdateId   = t.UpdateId,
                        UpdateName = t2.AccountName,
                        ImgPath    = t.ImgPath,
                    })
                                .ToListAsync();
                }


                //返回执行结果
                return(ResponseUtil <List <TBMPackageQueryModel> > .SuccessResult(queryData, totalNumber));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <List <TBMPackageQueryModel> > .FailResult(null, ex.Message));
            }
        }
Пример #30
0
        /// <summary>
        /// 查询TMMPurchaseApplyMain数据
        /// </summary>
        /// <param name="requestObject">响应结果对象</param>
        /// <returns></returns>
        public async Task <ResponseObject <List <TMMPurchaseApplyDetailQueryModel> > > GetToPurchaseListAsync(int requestObject)
        {
            var result = await GetDetailList(requestObject);

            return(ResponseUtil <List <TMMPurchaseApplyDetailQueryModel> > .SuccessResult(result.Data.Where(p => p.TransNum > 0).ToList()));
        }