public OnlineOrdersResultDto <List <DropDownItem> > GetSelectBy(string DropDown) { OnlineOrdersResultDto <List <DropDownItem> > res = new OnlineOrdersResultDto <List <DropDownItem> >() { StatusCode = 0, Message = "获取下拉基础信息失败", Ext1 = new List <DropDownItem>() }; Dictionary <int, string> result = new Dictionary <int, string>(); switch (DropDown.ToLower()) { case "negprice": result = EnumCenter.GetDictionaryForEnum <EnumCenter.Ppc_StockInfo_NegativeStockType>(); break; case "price": result = EnumCenter.GetDictionaryForEnum <EnumCenter.Ppc_StockInfo_PricePlatCount>(); break; } List <DropDownItem> dropdown = new List <DropDownItem>(); var listDropDown = result.ToList(); foreach (var item in listDropDown) { DropDownItem down = new DropDownItem(); down.key = item.Key; down.value = item.Value; dropdown.Add(down); } res.StatusCode = 1; res.Ext1 = dropdown; res.Message = "获取下拉基础信息成功"; return(res); }
public OnlineOrdersResultDto <UpTotalModel> ImportExcel(IFormFile formFile) { OnlineOrdersResultDto <UpTotalModel> result = new OnlineOrdersResultDto <UpTotalModel>() { StatusCode = 0, Message = "上传Excel失败", Ext1 = new UpTotalModel() { } }; if (Request.Form.Files == null || Request.Form.Files.Count == 0) { result.Message = "上传的Excel文件为空"; return(result); } try { IFormFile fileinput = Request.Form.Files[0]; var filename = ContentDispositionHeaderValue.Parse(fileinput.ContentDisposition).FileName; // 原文件名(包括路径) var extName = filename.Substring(filename.LastIndexOf('.')).Replace("\"", ""); // 扩展名 if (extName.ToLower() != ".xls" && extName.ToLower() != ".xlsx") { result.Message = "上传文件格式不正确"; return(result); } string shortfilename = $"{Guid.NewGuid()}{extName}"; // 新文件名 string fileSavePath = hostingEnvironment.WebRootPath + @"\upload\stock\"; //文件临时目录,导入完成后 删除 filename = fileSavePath + shortfilename; // 新文件名(包括路径) if (!Directory.Exists(fileSavePath)) { Directory.CreateDirectory(fileSavePath); } using (FileStream fs = System.IO.File.Create(filename)) // 创建新文件 { fileinput.CopyTo(fs); // 复制文件 fs.Flush(); // 清空缓冲区数据 } //读取Excel中的文件到DataTable中 using (Stream sm = System.IO.File.OpenRead(filename)) { DataTable dt = OfficeHelper.ReadStreamToDataTable(sm, extName, null, true, 4); List <UploadModel> models = dt.GetUpLoad(); result.StatusCode = 1; result.Message = "上传Excel成功"; result.Ext1.FileName = shortfilename; result.Ext1.listResult = models; result.Ext1.listHead = ConstUpLoadDic.StockHead.GetUpLoadHead(); } } catch (Exception ex) { result.StatusCode = 2; result.Message = ex.Message; } return(result); }
public OnlineOrdersResultDto <PageInfo <Ppc_UploadInfoOutPutPageListDto> > GetPageUploadinfo(Ppc_UploadInfoInputPageListDto input) { OnlineOrdersResultDto <PageInfo <Ppc_UploadInfoOutPutPageListDto> > res = new OnlineOrdersResultDto <PageInfo <Ppc_UploadInfoOutPutPageListDto> >() { StatusCode = 0, Message = "获取分页信息失败" }; var result = _service.GetPageUploadinfo(input); return(result); }
public OnlineOrdersResultDto AddPriceConfig(Ppc_PriceConfigInputDto input) { OnlineOrdersResultDto res = new OnlineOrdersResultDto() { StatusCode = 0, Message = "统一定价配置失败" }; res = _service.AddPriceConfig(input); return(res); }
public OnlineOrdersResultDto <PageInfo <Ppc_StockInfoOutputPageListDto> > GetPageStock(Ppc_StockInfoInputPageListDto input) { OnlineOrdersResultDto <PageInfo <Ppc_StockInfoOutputPageListDto> > res = new OnlineOrdersResultDto <PageInfo <Ppc_StockInfoOutputPageListDto> >() { StatusCode = 0, Message = "获取分页信息失败", Ext1 = new PageInfo <Ppc_StockInfoOutputPageListDto>() }; res = _service.GetPageStock(input); return(res); }
/// <summary> /// 返回有效的第三方平台的数据 /// </summary> /// <returns></returns> public OnlineOrdersResultDto <List <Ppc_PlatformConfigOutPutDto> > GetPlatform() { OnlineOrdersResultDto <List <Ppc_PlatformConfigOutPutDto> > res = new OnlineOrdersResultDto <List <Ppc_PlatformConfigOutPutDto> >() { StatusCode = 0, Message = "获取平台信息失败", Ext1 = new List <Ppc_PlatformConfigOutPutDto>() }; Expression <Func <Ppc_PlatformConfig, bool> > prediate = m => m.IsShow == 1; var selector = ExpExtension.GetSelector <Ppc_PlatformConfig, Ppc_PlatformConfigOutPutDto>(); var listplat = _iRepository.GetList <Ppc_PlatformConfig, Ppc_PlatformConfigOutPutDto>(prediate, null, null, selector); if (listplat == null || listplat.Count == 0 || listplat[0].ID.GetValueOrDefault(0) < 0) { return(res); } res.StatusCode = 1; res.Ext1 = listplat; res.Message = "获取平台信息成功"; return(res); }
/// <summary> /// 根据比价单号获取物料上传信息的详情 /// </summary> /// <param name="input"></param> /// <returns></returns> public OnlineOrdersResultDto <PageInfo <Ppc_StockInfoOutputPageListDto> > GetPageStock(Ppc_StockInfoInputPageListDto input) { OnlineOrdersResultDto <PageInfo <Ppc_StockInfoOutputPageListDto> > result = new OnlineOrdersResultDto <PageInfo <Ppc_StockInfoOutputPageListDto> >() { StatusCode = 0, Message = "获取信息失败", Ext1 = new PageInfo <Ppc_StockInfoOutputPageListDto>() }; if (string.IsNullOrWhiteSpace(input.UploadNo)) { result.Message = "上传比价单号不能为空"; return(result); } var updatetor = _iRepository.FindEntity <Ppc_UploadInfo>(m => m.UploadNO == input.UploadNo); if (updatetor == null) { result.Message = "上传记录未找到"; return(result); } if (updatetor.Status != 0) { result.StatusCode = 1; result.Message = "物料正在比对中"; return(result); } Expression <Func <Ppc_StockInfo, bool> > where = m => m.UploadNo == input.UploadNo; where = GetCommonWhere(where, input); var selector = ExpExtension.GetSelector <Ppc_StockInfo, Ppc_StockInfoOutputPageListDto>(); var pageEntity = _iRepository.GetConditionPageList <Ppc_StockInfo, Ppc_StockInfoOutputPageListDto>(where, input.PageIndex, input.PageSize, null, selector); var resultList = pageEntity.GetCommonPageEntityies <Ppc_StockInfoOutputPageListDto>(); if (resultList != null && resultList.ResultList != null && resultList.ResultList.Count > 0) { var list = GetExtendPropertities(resultList.ResultList); resultList.ResultList = list; } return(result); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public OnlineOrdersResultDto <PageInfo <Ppc_UploadInfoOutPutPageListDto> > GetPageUploadinfo(Ppc_UploadInfoInputPageListDto input) { OnlineOrdersResultDto <PageInfo <Ppc_UploadInfoOutPutPageListDto> > list = new OnlineOrdersResultDto <PageInfo <Ppc_UploadInfoOutPutPageListDto> >() { StatusCode = 1, Message = "获取信息成功" }; if (string.IsNullOrEmpty(SessionDataResult.LoginUseID)) { list.StatusCode = 0; list.Message = "登录信息已过期"; return(list); } ComparePriceToCrmApiResultDto <List <CrmPurchaseOutPutDto> > crmOutPut = new ComparePriceToCrmApi(_apiRequest).GetPurchaseBelongsFromCrm(new PurchaseInputDto() { CRMUserId = SessionDataResult.LoginUseID }).Result; if (crmOutPut.State <= 0) { list.StatusCode = 0; list.Message = crmOutPut.Message; return(list); } string[] ennameArray = crmOutPut.ReValue.Where(m => !string.IsNullOrWhiteSpace(m.EName)).Select(m => m.EName).Distinct().ToArray(); Expression <Func <Ppc_UploadInfo, bool> > exp = m => 1 > 0; if (ennameArray != null && ennameArray.Length > 0) { exp = exp.And(m => ennameArray.Contains(m.CreateName)); } Dictionary <int, Expression <Func <Ppc_UploadInfo, object> > > dic = new Dictionary <int, Expression <Func <Ppc_UploadInfo, object> > >(); dic.Add(2, m => m.CreateTime); var selector = ExpExtension.GetSelector <Ppc_UploadInfo, Ppc_UploadInfoOutPutPageListDto>(); var pageEntity = _iRepository.GetConditionPageList <Ppc_UploadInfo, Ppc_UploadInfoOutPutPageListDto>(exp, input.PageIndex, input.PageSize, dic, selector); list.Ext1 = pageEntity.GetCommonPageEntityies <Ppc_UploadInfoOutPutPageListDto>(); return(list); }
public OnlineOrdersResultDto <string> ExportStock(Ppc_PriceConfigInputDto input) { OnlineOrdersResultDto <string> res = new OnlineOrdersResultDto <string>() { StatusCode = 0, Message = "excel导出失败", }; var updatetor = _iRepository.FindEntity <Ppc_UploadInfo>(m => m.UploadNO == input.UploadNo); if (updatetor == null) { res.Message = "上传记录未找到"; return(res); } if (updatetor.Status != 0) { res.Message = "物料正在比对中,请等程序运行完成后再导出上传的库存"; return(res); } res.StatusCode = 1; res.Message = "excel导出进行中"; res.Ext1 = "/Export/ExportStockUpload?UploadNo=" + input.UploadNo; return(res); }
public OnlineOrdersResultDto UploadStock(UploadStockInputDto inputDto) { OnlineOrdersResultDto result = new OnlineOrdersResultDto() { StatusCode = 0, Message = "保存数据失败" }; inputDto.FileName = "d9d7556c-6283-437c-8b4e-1ac9bb921a47.xlsx"; inputDto.Remark = "测试"; inputDto.UpFileds = new List <UpLoadHead>() { new UpLoadHead() { Key = "型号", Value = "物料型号" }, new UpLoadHead() { Key = "品牌", Value = "物料型号" }, new UpLoadHead() { Key = "库存", Value = "" }, new UpLoadHead() { Key = "SPQ", Value = "SPQ" }, new UpLoadHead() { Key = "MOQ", Value = "MOQ" }, new UpLoadHead() { Key = "供应商报价", Value = "供应商报价" }, new UpLoadHead() { Key = "批次", Value = "批次" }, new UpLoadHead() { Key = "封装", Value = "封装" }, new UpLoadHead() { Key = "描述", Value = "描述" }, new UpLoadHead() { Key = "货期(SZ)", Value = "货期(SZ)" }, new UpLoadHead() { Key = "货期(HK)", Value = "货期(HK)" }, new UpLoadHead() { Key = "阶梯", Value = "阶梯" }, }; result = _service.UploadStock(inputDto); return(result); }
/// <summary> /// 统一设置价格策略 /// </summary> /// <param name="input"></param> /// <returns></returns> public OnlineOrdersResultDto AddPriceConfig(Ppc_PriceConfigInputDto input) { OnlineOrdersResultDto result = new OnlineOrdersResultDto() { StatusCode = 0, Message = "统一设置价格策略失败" }; if (string.IsNullOrWhiteSpace(input.UploadNo)) { result.Message = "比价单号不能为空"; return(result); } var updatetor = _iRepository.FindEntity <Ppc_UploadInfo>(m => m.UploadNO == input.UploadNo); if (updatetor == null) { result.Message = "上传记录未找到"; return(result); } if (updatetor.Status != 0) { result.Message = "物料正在比对中,请等程序运行完成后再设置价格策略"; return(result); } if (input.AdjustType == 1) { //自动调价过滤 if (input.MaxProfitRate.GetValueOrDefault(0) <= 0) { result.Message = "最高毛利率不能为空"; return(result); } if (input.MinProfitRate.GetValueOrDefault(0) <= 0) { result.Message = "最低毛利率不能为空"; return(result); } if (input.PriceRatio.GetValueOrDefault(0) <= 0) { result.Message = "跟价系数不能为空"; return(result); } if (input.PlatformIDArray == null || input.PlatformIDArray.Length == 0) { result.Message = "对标平台必须选择"; return(result); } if (input.IsUnpacking == 1) { if (input.IsPriceLadder == 1) { //不使用对标平台梯度价格 if (input.CustermerCongigList == null || input.CustermerCongigList.Count == 0) { result.Message = "未提交有效的价格梯度"; return(result); } } //可拆包 } else if (input.IsUnpacking == 2) { if (input.CustomerSupplierList == null || input.CustomerSupplierList.Count == 0) { result.Message = "未提交有效的SPQ价格梯度"; return(result); } } } else if (input.AdjustType == 2) { //手动条件过滤 if (input.CurrentProfitRate.GetValueOrDefault(0) < 0) { result.Message = "调整的当前利率不能为空"; return(result); } } if (input.AdjustArange.GetValueOrDefault(0) == 1) { if (input.StockIDArray == null || input.StockIDArray.Length == 0) { result.Message = "未勾选任何有效的物料"; return(result); } _iRepository.UpdateEntity <Ppc_StockInfo>(m => input.StockIDArray.Contains(m.PID), t => new Ppc_StockInfo { Status = 2 }); } else if (input.AdjustArange.GetValueOrDefault(0) == 2) { Ppc_StockInfoInputPageListDto inputwhere = new Ppc_StockInfoInputPageListDto() { UploadNo = input.UploadNo, Model = input.Model, Brand = input.Brand, MinProfitBegin = input.MinProfitBegin, MinProfitEnd = input.MinProfitEnd, ProfitRateBegin = input.ProfitRateBegin, ProfitRateEnd = input.ProfitRateEnd, NegativeStockType = input.NegativeStockType, PricePlatCount = input.PricePlatCount, HeadNegativeStockType = input.HeadNegativeStockType, HeadPricePlatCount = input.HeadPricePlatCount, }; var where = GetCommonWhere(m => 1 == 1, inputwhere); _iRepository.UpdateEntity <Ppc_StockInfo>(where, t => new Ppc_StockInfo { Status = 2 }); } #region 更新上传记录的操作次数,将上传信息更新为待对比 _iRepository.UpdateEntity <Ppc_UploadInfo>(m => m.UploadNO == input.UploadNo, t => new Ppc_UploadInfo { Status = 1 }); #endregion #region 存在未删除的价格配置数据,就把它置为删除 var configExs = _iRepository.FindEntity <Ppc_PriceConfig>(m => m.UploadNo == input.UploadNo && m.IsDelete == 1); if (configExs != null && configExs.ID.GetValueOrDefault(0) > 0) { _iRepository.UpdateEntity <Ppc_PriceConfig>(m => m.UploadNo == input.UploadNo && m.IsDelete == 1, t => new Ppc_PriceConfig { IsDelete = 0 }); } #endregion List <Ppc_PlatformPriceConfig> itemList = new List <Ppc_PlatformPriceConfig>(); Ppc_PriceConfig config = new Ppc_PriceConfig(); config.UploadNo = input.UploadNo; if (input.AdjustType == 1) { config.AdjustType = 1; config.MaxProfitRate = input.MaxProfitRate / 100; config.MinProfitRate = input.MinProfitRate / 100; config.PriceRatio = input.PriceRatio; #region 获取所有的对标平台信息 List <Ppc_PlatformConfig> platList = _iRepository.GetEntitiesListByConditions <Ppc_PlatformConfig>(m => input.PlatformIDArray.Contains(m.ID), null); if (platList == null || platList.Count == 0) { result.Message = "平台信息未找到"; return(result); } #endregion config.ComparePlatform = string.Join(",", platList.Select(m => m.PlatformType).Distinct().ToArray()); config.IsUnpacking = input.IsUnpacking; if (input.IsUnpacking == 1) { //自动调价 if (input.IsPriceLadder == 0) { //使用对标平台价格策略 config.IsPriceLadder = 1; } else if (input.IsPriceLadder == 1) { config.IsPriceLadder = 0; foreach (var item in input.CustermerCongigList) { Ppc_PlatformPriceConfig model = new Ppc_PlatformPriceConfig(); model.MaxVal = item.Qty; model.ProfitRate = item.ProfitRate / 100M; itemList.Add(model); } } } else if (input.IsUnpacking == 2) { //写入ppc_platformpriceconfig foreach (var item in input.CustomerSupplierList) { Ppc_PlatformPriceConfig model = new Ppc_PlatformPriceConfig(); model.MaxVal = item.Qty; model.ProfitRate = item.ProfitRate / 100M; itemList.Add(model); } } } else if (input.AdjustType == 2) { //手动条件 config.AdjustType = 2; config.ChangeProfitRate = input.CurrentProfitRate / 100M; } var rowCount = _iRepository.InsertIdentity <Ppc_PriceConfig>(config); if (rowCount > 0) { if (itemList != null && itemList.Count > 0) { itemList.ForEach(m => { m.PriceConfigID = rowCount; }); var ccCount = _iRepository.InsertEntityList <Ppc_PlatformPriceConfig>(itemList); if (ccCount < 0) { result.Message = "平台价格配置写入失败"; return(result); } } result.StatusCode = 1; result.Message = "设置价格策略成功"; } else { result.Message = "价格策略设置失败"; } return(result); }
/// <summary> /// 点击保存按键写入数据库操作 /// </summary> /// <param name="inputDto"></param> /// <returns></returns> public OnlineOrdersResultDto UploadStock(UploadStockInputDto inputDto) { OnlineOrdersResultDto res = new OnlineOrdersResultDto() { StatusCode = 0, Message = "保存数据失败" }; if (string.IsNullOrWhiteSpace(inputDto.FileName)) { res.Message = "Excel文件名系统未找到"; return(res); } string fileSavePath = hostingEnvironment.WebRootPath + @"\upload\stock\"; string filename = fileSavePath + inputDto.FileName; if (!File.Exists(filename)) { res.Message = "系统未找到上传的文件"; return(res); } if (inputDto.UpFileds == null || inputDto.UpFileds.Count == 0) { res.Message = "请下方拖拽要上传的字段"; return(res); } #region 获取表头最新的流水号 var flownumber = string.Empty; string preFixNo = "BJ" + DateTime.Now.Date.ToString("yyyy-MM-dd").Replace("-", ""); var uploadinfo = _iRepository.GetList <Ppc_UploadInfo, Ppc_UploadInfo>(m => m.UploadNO.StartsWith(preFixNo), null, null, m => new Ppc_UploadInfo { UploadNO = Kogel.Dapper.Extension.Function.Max(m.UploadNO) }); if (uploadinfo == null || uploadinfo.Count == 0 || string.IsNullOrWhiteSpace(uploadinfo[0].UploadNO)) { flownumber = preFixNo + "0001"; } else { var dbnumber = uploadinfo.FirstOrDefault().UploadNO; flownumber = preFixNo + Common.GetMaxNo(dbnumber); } if (string.IsNullOrEmpty(flownumber)) { res.Message = "未生成比价流水号"; return(res); } #endregion string extName = Path.GetExtension(filename); List <Ppc_StockInfo> stockList = new List <Ppc_StockInfo>(); //物料信息表 List <Ppc_UploadStockStepqty> stepList = new List <Ppc_UploadStockStepqty>(); //阶梯表 StringBuilder sb = new StringBuilder(); StringBuilder sbTotal = new StringBuilder(); DateTime dtNow = DateTime.Now; //读取Excel数据 using (Stream sm = System.IO.File.OpenRead(filename)) { ISheet sheet = null; IRow firstRow = null; Dictionary <string, int> Dicols = new Dictionary <string, int>(); //数据开始行(排除标题行) int startRow = 0; try { //根据文件流创建excel数据结构,NPOI的工厂类WorkbookFactory会自动识别excel版本,创建出不同的excel数据结构 IWorkbook workbook = extName.ToLower() == ".xls" ? new HSSFWorkbook(sm) : WorkbookFactory.Create(sm); //如果没有指定的sheetName,则尝试获取第一个sheet sheet = workbook.GetSheetAt(0); if (sheet != null) { firstRow = sheet.GetRow(0); //一行最后一个cell的编号 即总的列数 int cellCount = firstRow.LastCellNum; for (int i = firstRow.FirstCellNum; i < cellCount; ++i) { ICell cell = firstRow.GetCell(i); if (cell != null) { string cellValue = cell.StringCellValue; if (!string.IsNullOrWhiteSpace(cellValue) && !Dicols.ContainsKey(cellValue)) { Dicols.Add(cellValue, i); } } } startRow = sheet.FirstRowNum + 1; //最后一列的标号 int rowCount = sheet.LastRowNum; Guid guidRow = Guid.Empty; //关联物料表与价格梯度表; for (int i = startRow; i <= rowCount; i++) { bool xinghaoRowFlag = true;//标记是否为型号行,默认为是型号行 Ppc_StockInfo dbModel = new Ppc_StockInfo(); IRow row = sheet.GetRow(i); #region Excel已经保存在服务器上面,客户端怎么拖拽上传都无法改变行的性质(要么物料行,要么阶梯行) ICell cell = row.GetCell(0); if (cell != null && !string.IsNullOrWhiteSpace(cell.ToString().Trim())) { guidRow = Guid.NewGuid(); xinghaoRowFlag = true; } else if (i == 1) { res.Message = "第一行数据行必须为型号行"; return(res); } else { xinghaoRowFlag = false; } #endregion if (row == null || row.FirstCellNum < 0) { continue; //没有数据的行默认是null } bool IsEmptyRow = false; //是否是空行判断 for (int j = row.FirstCellNum; j < cellCount; j++) { string columnname = firstRow.GetCell(j).StringCellValue; //excel中上传的列名对应数据库中的列名称 string uploadcolname = inputDto.UpFileds.Find(m => m.Key == columnname) != null?inputDto.UpFileds.Find(m => m.Value == columnname).Value : string.Empty; //用户拖拽的实际列名 if (xinghaoRowFlag) { IsEmptyRow = SetDbModelData(dbModel, Dicols, columnname, uploadcolname, row, i, sb, flownumber, dtNow, IsEmptyRow, stepList, guidRow.ToString()); dbModel.Guid = guidRow.ToString(); } else { //针对阶梯行的数据检查 IsEmptyRow = SetDbModelLadderData(dbModel, Dicols, columnname, uploadcolname, row, i, sb, flownumber, dtNow, IsEmptyRow, stepList, guidRow.ToString()); } } if (sb.Length == 0 && xinghaoRowFlag) { stockList.Add(dbModel); } if (!IsEmptyRow) { break; } if (sb.Length > 0 && IsEmptyRow) { sbTotal.Append(sb.ToString()); } } } } catch (Exception ex) { throw ex; } } #region 写入数据库 if (sbTotal != null && sbTotal.Length > 0) { res.Message = sbTotal.ToString(); return(res); } if (stockList != null && stockList.Count > 0) { var rowsCount = _iRepository.InsertEntityList <Ppc_StockInfo>(stockList); if (rowsCount > 0) { Ppc_UploadInfo head = new Ppc_UploadInfo() { UploadNO = flownumber, Des = inputDto.Remark, Status = (int)EnumCenter.Ppc_UploadInfo_Status.InterfaceDocking, CreateTime = dtNow, UpdateTime = dtNow, CreateID = SessionDataResult.LoginUseID, CreateName = SessionDataResult.LoginUseName }; var headCount = _iRepository.Insert <Ppc_UploadInfo>(head); if (headCount > 0) { #region 写入价格阶梯配置表 if (stepList != null && stepList.Count > 0) { var stepCount = _iRepository.InsertEntityList <Ppc_UploadStockStepqty>(stepList); if (stepCount < 0) { res.Message = "数据导入成功但是阶梯数据未导入成功"; return(res); } } #endregion res.StatusCode = 1; res.Message = "导入库存数据成功"; return(res); } else { res.Message = "写入上传信息失败"; return(res); } } else { res.Message = "写入上传物料信息失败"; return(res); } } #endregion return(res); }