/// <summary> /// 获取T_BM_CustomerFile主表数据数据 /// </summary> /// <param name="requestObject">Get请求参数</param> /// <param name="currentUser"></param> /// <returns>返回响应结果对象,包括响应代码,查询操作结果</returns> public async Task <ResponseObject <List <TBMCustomerFileQueryModel> > > GetMainListAsync(RequestGet requestObject, CurrentUser currentUser) { try { List <TBMCustomerFileQueryModel> queryData = new List <TBMCustomerFileQueryModel>(); //查询结果集对象 RefAsync <int> totalNumber = -1; //总记录数 var query = _db.Instance.Queryable <TBMCustomerFileDbModel, TBMCustomerContactDbModel>((t, t1) => new object[] { JoinType.Left, t1.CustomerId == t.ID }).Where((t, t1) => t.CompanyId == currentUser.CompanyID && t.DeleteFlag == false); //数据字典 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 conditionals = SqlSugarUtil.GetConditionalModels(customerConditions1); foreach (ConditionalModel item in conditionals) { item.FieldName = $"t1.{item.FieldName}"; } query.Where(conditionals); } var customerConditions2 = requestObject.QueryConditions.Where(p => p.Column.ToLower() != "contactname").ToList(); if (customerConditions2 != null && customerConditions2.Count() > 0) { var conditionals = SqlSugarUtil.GetConditionalModels(customerConditions2); 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 <TBMCustomerFileDbModel>(item.Column); if (exp == null) { continue; } if (item.Condition.ToLower() != "asc" && item.Condition.ToLower() != "desc") { continue; } query.OrderBy($"{item.Column} {item.Condition}"); } } var query1 = query.Select((t, t1) => t).Distinct(); List <TBMCustomerFileDbModel> queryDataTemp = new List <TBMCustomerFileDbModel>(); //执行查询 if (requestObject.IsPaging) { queryDataTemp = await query1 .Where(t => !t.DeleteFlag) .Select((t) => t) .ToPageListAsync(requestObject.PageIndex, requestObject.PageSize, totalNumber); } else { queryDataTemp = await query1 .Where(t => !t.DeleteFlag) .Select(t => t) .ToListAsync(); } queryDataTemp.ForEach((x) => { var itemEnity = ExpressionGenericMapper <TBMCustomerFileDbModel, TBMCustomerFileQueryModel> .Trans(x); itemEnity.ChildList = new List <TBMCustomerContactQueryModel>(); foreach (var citem in x.Child.OrderBy(p => p.Priority)) { var citemEnity = ExpressionGenericMapper <TBMCustomerContactDbModel, TBMCustomerContactQueryModel> .Trans(citem); itemEnity.ChildList.Add(citemEnity); } var item = dics.Where(p => p.ID == x.CustomerTypeId).FirstOrDefault(); if (item != null) { itemEnity.CustomerTypeName = 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 <TBMCustomerFileQueryModel> > .SuccessResult(queryData, totalNumber)); } catch (Exception ex) { //返回查询异常结果 return(ResponseUtil <List <TBMCustomerFileQueryModel> > .FailResult(null, ex.Message)); } }
public async Task <ResponseObject <TWMProductionWhMainQueryModel> > GetWholeMainData(int iMainId, CurrentUser currentUser) { try { RequestGet requestGet = new RequestGet() { IsPaging = false, QueryConditions = new List <QueryCondition>() { new QueryCondition() { Column = "Id", Condition = ConditionEnum.Equal, Content = iMainId.ToString() } } }; var allMain = await GetMainListAsync(requestGet, currentUser); var mainModel = allMain.Data.FirstOrDefault(); var materList = BasicCacheGet.GetMaterial(currentUser); var dicList = BasicCacheGet.GetDic(currentUser); var detailModels = await _db.Instance.Queryable <TWMProductionWhDetailDbModel, TWMProductionWhMainDbModel, TBMMaterialFileDbModel, TMMWhApplyMainDbModel, TMMWhApplyDetailDbModel, TMMProductionOrderDetailDbModel, TMMColorSolutionMainDbModel, TBMPackageDbModel, TBMDictionaryDbModel, TSMUserAccountDbModel, TBMDictionaryDbModel>( (t, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) => new object[] { JoinType.Inner, t.MainId == t0.ID, JoinType.Inner, t.MaterialId == t1.ID, JoinType.Inner, t0.SourceId == t2.ID, JoinType.Inner, t.ProOrderDetailId == t3.ID, JoinType.Inner, t3.ProOrderDetailId == t4.ID, JoinType.Left, t4.ColorSolutionId == t5.ID, JoinType.Left, t4.PackageId == t6.ID, JoinType.Left, t.WorkshopId == t7.ID, JoinType.Left, t4.PrincipalId == t8.ID, JoinType.Left, t.SiteId == t9.ID } ).Select((t, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) => new TWMProductionWhDetailQueryModel { ID = t.ID, MainId = t.MainId, MaterialId = t.MaterialId, MaterialName = t1.MaterialName, MaterialCode = t1.MaterialCode, WarehouseId = t.WarehouseId, ActualNum = t.ActualNum, ProActualNum = t.ProActualNum, UnitPrice = t.UnitPrice, Amount = t.Amount, MaterialTypeId = t1.MaterialTypeId, //MaterialTypeName = t1.TypeName, ColorId = t1.ColorId, //ColorName = t2.DicValue, BaseUnitId = t1.BaseUnitId, //BaseUnitName = t3.DicValue, WarehouseUnitId = t1.WarehouseUnitId, //WarehouseUnitName = t4.DicValue, WarehouseRate = t1.WarehouseRate, ProduceRate = t1.ProduceRate, ProduceUnitId = t1.ProduceUnitId, //ProduceUnitName = t5.DicValue, Spec = t1.Spec, Remark = t.Remark, SourceCode = t2.WhApplyNo, TransNum = t3.TransNum, PackageId = t4.PackageId, ColorSolutionId = t4.ColorSolutionId, ColorSolutionName = t5.SolutionCode, PackageCode = t6.DicCode, PackageName = t6.DicValue, WorkshopName = t7.DicValue, PrincipalName = t8.AccountName, ProOrderDetailId = t.ProOrderDetailId, SiteName = t9.DicValue }) .Where(t => t.MainId == iMainId) .ToListAsync(); detailModels.ForEach((x) => { var thisMaterial = materList.Where(p => p.ID == x.MaterialId).FirstOrDefault(); if (mainModel.AuditStatus != 2) { x.TransNum = x.TransNum + x.ProActualNum; } x.MaterialTypeName = thisMaterial.MaterialTypeName; x.ColorName = thisMaterial.ColorName; x.BaseUnitName = thisMaterial.BaseUnitName; x.WarehouseUnitName = thisMaterial.WarehouseUnitName; x.ProduceUnitName = thisMaterial.ProduceUnitName; }); mainModel.ChildList = detailModels; return(ResponseUtil <TWMProductionWhMainQueryModel> .SuccessResult(mainModel)); } catch (Exception ex) { return(ResponseUtil <TWMProductionWhMainQueryModel> .FailResult(null)); } }
/// <summary> /// 新增T_MM_ColorSolutionMain数据 /// </summary> /// <param name="requestObject">Post请求参数</param> /// <returns>返回响应结果对象,包括响应代码,新增操作结果</returns> public async Task <ResponseObject <bool> > PostAsync(RequestPost <TMMColorSolutionMainAddModel> 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(); //生成物料 TBMMaterialFileDbModel material = new TBMMaterialFileDbModel(); material.MaterialCode = CreateNo(currentUser.CompanyID); 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 <TMMColorSolutionDetailAddModel>, 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)); } }
/// <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> /// 新增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)); } }
public async Task <TMMPickApplyMainQueryModel> GetTopMainData(int iMainId, CurrentUser currentUser) { try { var mainModel = await _db.Instance.Queryable <TMMPickApplyMainDbModel, TSMUserAccountDbModel, TSMUserAccountDbModel>( (t, t1, t2) => new object[] { JoinType.Left, t.OperatorId == t1.ID, JoinType.Left, t.AuditId == t2.ID }).Where((t, t1, t2) => t.DeleteFlag == false && t.CompanyId == currentUser.CompanyID) .Select((t, t1, t2) => new TMMPickApplyMainQueryModel { ID = t.ID, SourceId = t.SourceId, PickNo = t.PickNo, 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, IsShowEdit = (t.AuditStatus != 2 && t.OperatorId == currentUser.UserID) ? true : false }) .Where(t => t.ID == iMainId) .FirstAsync(); var detailModels = await _db.Instance.Queryable <TMMPickApplyDetailDbModel, TBMMaterialFileDbModel, TBMDictionaryTypeDbModel, TBMDictionaryDbModel, TBMDictionaryDbModel, TBMDictionaryDbModel>( (t, t0, t1, t2, t3, t4) => 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.WarehouseUnitId == t4.ID }).Where((t, t0, t1, t2, t3, t4) => t.MainId == iMainId && t.TransNum > 0) .Select((t, t0, t1, t2, t3, t4) => new TMMPickApplyDetailQueryModel { MaterialId = t.MaterialId, TransNum = t.TransNum, MaterialName = t0.MaterialName, MaterialCode = t0.MaterialCode, MaterialTypeId = t0.MaterialTypeId, //MaterialTypeName = t1.TypeName, ColorId = t0.ColorId, //ColorName = t2.DicValue, BaseUnitId = t0.BaseUnitId, //BaseUnitName = t3.DicValue, WarehouseUnitId = t0.WarehouseUnitId, //WarehouseUnitName = t4.DicValue, WarehouseRate = t0.WarehouseRate, ProduceRate = t0.ProduceRate, ProduceUnitId = t0.ProduceUnitId, Spec = t0.Spec, }) .ToListAsync(); var materList = BasicCacheGet.GetMaterial(currentUser); var dicList = BasicCacheGet.GetDic(currentUser); detailModels.ForEach((x) => { var thisMaterial = materList.Where(p => p.ID == x.MaterialId).FirstOrDefault(); x.MaterialTypeName = thisMaterial.MaterialTypeName; x.ColorName = thisMaterial.ColorName; x.BaseUnitName = thisMaterial.BaseUnitName; x.WarehouseUnitName = thisMaterial.WarehouseUnitName; x.ProduceUnitName = thisMaterial.ProduceUnitName; }); mainModel.ChildList = detailModels; return(mainModel); } catch (Exception ex) { return(null); } }
public async Task <ResponseObject <TWMProductionMainQueryModel> > GetWholeMainData(int iMainId, CurrentUser currentUser) { try { RequestGet requestGet = new RequestGet() { IsPaging = false, QueryConditions = new List <QueryCondition>() { new QueryCondition() { Column = "Id", Condition = ConditionEnum.Equal, Content = iMainId.ToString() } } }; var allMain = await GetMainListAsync(requestGet, currentUser); var mainModel = allMain.Data.FirstOrDefault(); var materList = BasicCacheGet.GetMaterial(currentUser); var dicList = BasicCacheGet.GetDic(currentUser); var detailModels = await _db.Instance.Queryable <TWMProductionDetailDbModel, TWMProductionMainDbModel, TBMMaterialFileDbModel, TMMPickApplyMainDbModel, TMMPickApplyDetailDbModel>( (t, t0, t1, t2, t3) => new object[] { JoinType.Inner, t.MainId == t0.ID, JoinType.Inner, t.MaterialId == t1.ID, JoinType.Inner, t0.SourceId == t2.ID, JoinType.Inner, t.PickApplyDetailId == t3.ID } ).Select((t, t0, t1, t2, t3) => new TWMProductionDetailQueryModel { ID = t.ID, MainId = t.MainId, MaterialId = t.MaterialId, MaterialName = t1.MaterialName, MaterialCode = t1.MaterialCode, WarehouseId = t.WarehouseId, ActualNum = t.ActualNum, PickActualNum = t.PickActualNum, PickApplyDetailId = t.PickApplyDetailId, UnitPrice = t.UnitPrice, Amount = t.Amount, MaterialTypeId = t1.MaterialTypeId, //MaterialTypeName = t1.TypeName, ColorId = t1.ColorId, //ColorName = t2.DicValue, BaseUnitId = t1.BaseUnitId, //BaseUnitName = t3.DicValue, WarehouseUnitId = t1.WarehouseUnitId, //WarehouseUnitName = t4.DicValue, WarehouseRate = t1.WarehouseRate, ProduceRate = t1.ProduceRate, ProduceUnitId = t1.ProduceUnitId, //ProduceUnitName = t5.DicValue, Spec = t1.Spec, Remark = t.Remark, TransNum = t3.TransNum, }) .Where(t => t.MainId == iMainId) .ToListAsync(); detailModels.ForEach((x) => { var thisMaterial = materList.Where(p => p.ID == x.MaterialId).FirstOrDefault(); if (mainModel.AuditStatus != 2) { x.TransNum = x.TransNum + x.PickActualNum; } x.MaterialTypeName = thisMaterial.MaterialTypeName; x.ColorName = thisMaterial.ColorName; x.BaseUnitName = thisMaterial.BaseUnitName; x.WarehouseUnitName = thisMaterial.WarehouseUnitName; x.ProduceUnitName = thisMaterial.ProduceUnitName; TWMStaQuery tWMStaQuery = new TWMStaQuery(); tWMStaQuery.MaterialId = x.MaterialId; tWMStaQuery.WarehouseId = x.WarehouseId; if (mainModel.AuditStatus != 2) { tWMStaQuery.EditID = mainModel.ID; tWMStaQuery.OperateType = OperateEnum.Product; } x.AvailableNum = _staticInventory.GeTWMCountModel(tWMStaQuery).AvaiableNum; }); mainModel.ChildList = detailModels; return(ResponseUtil <TWMProductionMainQueryModel> .SuccessResult(mainModel)); } catch (Exception ex) { return(ResponseUtil <TWMProductionMainQueryModel> .FailResult(null)); } }