Exemple #1
0
        public ActionResult <object> GetDictByTypeList(int dictType, int?pDictKey)
        {
            var crmDictList = _cache.GetOrCreate(_allDictKey, (entry) => _repository.GetDicList());
            var query       = crmDictList.Where(t => t.DictType == dictType);

            if (pDictKey != null)
            {
                query = query.Where(t => t.PDictKey == pDictKey);
            }
            return(query.OrderBy(t => t.Sort).Select(t => new { key = t.DictKey, value = t.DictValue }).ResponseSuccess());
        }
Exemple #2
0
        public ActionResult <object> ImportProduct()
        {
            var filePath = Utils.FileSave(HttpContext, "xlsx");

            if (filePath.IsNullOrWhiteSpace())
            {
                return(false.ResponseDataError("上传文件失败,格式不对或超过限制文件大小"));
            }
            var errorMsgList = new List <string>();
            var table        = NpoiExcelHelper.ExcelToTable(filePath);
            var importData   = new List <CrmProductScrewEntity>();

            if (table.Rows.Count > 0)
            {
                var importDataTemp = NpoiExcelHelper.GetEntityFromDataTable <CrmProductScrewView>(table);
                var dictList       = _cache.GetOrCreate("dictcontroller_getcrmdiclist", (entry) => _repositoryDict.GetDicList()); //类别id,缓存key和字典那边一样

                var index = 1;
                foreach (var item in importDataTemp)
                {
                    index++;
                    if (dictList.FirstOrDefault(t => t.DictKey == item.ProductType && t.DictType == (int)CrmDictTypeEnum.产品类型) == null ||
                        dictList.FirstOrDefault(t => t.PDictKey == item.ProductType && t.DictKey == item.ProductNameType && t.DictType == (int)CrmDictTypeEnum.产品名称) == null ||
                        dictList.FirstOrDefault(t => t.DictKey == item.Material && t.DictType == (int)CrmDictTypeEnum.产品材质) == null ||
                        dictList.FirstOrDefault(t => t.DictKey == item.Exterior && t.DictType == (int)CrmDictTypeEnum.产品外观) == null ||
                        item.Specification.IsNullOrWhiteSpace() ||
                        item.PackageWeight == 0 ||
                        item.ProposedPrice == 0 ||
                        item.RetailPrice == 0 ||
                        item.PurchasePrice == 0 ||
                        item.CostPrice == 0
                        )
                    {
                        errorMsgList.Add($"{index}行格式错误");
                        continue;   //跳出循环
                    }
                    var model = new CrmProductScrewEntity().CopyFrom(item);
                    model.ModifyTime = DateTime.Now;
                    model.Status     = 1;
                    importData.Add(model);
                }
            }
            var isok = _repository.AddBatchProductScrew(importData);
            var msg  = !isok ? "存入数据时失败" : errorMsgList.Count == 0 ? "全部导入成功" : "【部分失败】" + string.Join("|", errorMsgList);

            return(isok.ResponseSuccessFailure(msg));
        }