public void UpdateMaxIndex(RaeClassContentType contentType, int gap = 1)
        {
            var query = raeClassContext.SerialNumberSet.Where(x => x.FContentType.Equals(contentType.ToString())).FirstOrDefault();

            query.FCurrentGeneratedIndex += gap;
            raeClassContext.SaveChanges();
        }
Пример #2
0
        private List <BaseFormContent> GetBaseFormContents(RaeClassContentType contentType, List <FormContent> formContents)
        {
            List <BaseFormContent> baseFormContents = new List <BaseFormContent>();

            formContents.ForEach(item => baseFormContents.Add(GetBaseFormContent(contentType, item)));
            return(baseFormContents);
        }
        public async Task <JsonResult> Save(RaeClassContentType contentType, FormContent formContent)
        {
            FormContent _formContent = null;

            if (string.IsNullOrEmpty(formContent.fnumber))
            {
                _formContent = await formContentRepository.AddAsync(contentType, formContent);
            }
            else
            {
                if (!formContent.fdocStatus.Equals(DocStatus.SAVE) && !formContent.fdocStatus.Equals(DocStatus.AUDIT))
                {
                    string msg = "只有保存或审核状态才允许保存,此文章不符合该条件!";
                    return(Json(new { isok = false, errmsg = msg }));
                }
                formContent.fdocStatus = DocStatus.SAVE;
                _formContent           = await formContentRepository.UpdateAsync(formContent);
            }

            if (_formContent != null)
            {
                return(Json(new { isok = true, content = _formContent }));
            }
            else
            {
                return(Json(new { isok = false }));
            }
        }
 /// <summary>
 /// isModify=true 修改
 /// isModify=false 新增
 /// </summary>
 /// <param name="read"></param>
 /// <param name="isModify"></param>
 /// <returns></returns>
 public IActionResult FormContentDetail(RaeClassContentType contentType, string fnumber)
 {
     if (string.IsNullOrEmpty(fnumber))
     {
         fnumber = string.Empty;
     }
     ViewData["fnumber"]     = fnumber;
     ViewData["contentType"] = contentType;
     return(View());
 }
Пример #5
0
        public static string GetRecordFilePrefix(RaeClassContentType contentType)
        {
            switch (contentType)
            {
            case RaeClassContentType.Read: return(CONST.WX_READ_RECORD_PREFIX);

            case RaeClassContentType.Listen: return(CONST.WX_LISTEN_RECORD_PREFIX);

            case RaeClassContentType.Spoken: return(CONST.WX_SPOKEN_RECORD_PREFIX);
            }
            return(string.Empty);
        }
Пример #6
0
        public async Task <int> AddListAsync(RaeClassContentType contentType, List <FormContent> formContents)
        {
            FillFormContents(contentType, ref formContents);
            List <BaseFormContent> baseFormContents = GetBaseFormContents(contentType, formContents);
            await context.BaseFormContentSet.AddRangeAsync(baseFormContents);

            int res = await context.SaveChangesAsync();

            if (res == 1)
            {
                serialNumberRepository.UpdateMaxIndex(contentType);
            }
            return(res);
        }
Пример #7
0
        private BaseFormContent GetBaseFormContent(RaeClassContentType contentType, FormContent formContent)
        {
            BaseFormContent baseFormContent = new BaseFormContent();

            baseFormContent.FContentType = contentType.ToString();
            baseFormContent.FDocStatus   = DocStatus.SAVE;
            baseFormContent.FNumber      = formContent.fnumber;
            baseFormContent.FName        = formContent.fname;
            baseFormContent.FLevel       = formContent.flevel;
            baseFormContent.FJsonData    = JsonHelper.SerializeObject(formContent);
            baseFormContent.FCreateTime  = DateTime.Now;
            baseFormContent.FModifyTime  = DateTime.Now;
            return(baseFormContent);
        }
        public async Task <FileResult> DownLoadJsonFile(RaeClassContentType contentType, string fnumbers)
        {
            StringBuilder      sb          = new StringBuilder();
            List <string>      _fnumbers   = fnumbers.Split(',').ToList();
            List <FormContent> formContens = await formContentRepository.GetFormContentListAsync(_fnumbers);

            formContens.Where(x => x.fdocStatus.Equals(DocStatus.AUDIT)).ToList().ForEach(item => {
                item.frecordFileId1 = CommonUtils.GetRecordFilePrefix(contentType) + item.frecordFileId1;
                item.frecordFileId2 = CommonUtils.GetRecordFilePrefix(contentType) + item.frecordFileId2;
                sb.AppendLine(JsonHelper.SerializeObject(item));
            });
            byte[] fileContents = System.Text.Encoding.Default.GetBytes(sb.ToString());
            return(File(fileContents, System.Net.Mime.MediaTypeNames.Application.Octet, contentType + "-[" + DateTime.Now.ToString() + "].json")); //关键语句
        }
        public async Task <JsonResult> Submit(RaeClassContentType contentType, List <FormContent> formContents)
        {
            formContents.ForEach(item => item.fdocStatus = DocStatus.AUDIT);
            int querySaveStatusCount = formContents.Where(x => string.IsNullOrEmpty(x.fnumber)).Count();

            if (querySaveStatusCount > 0)
            {
                throw new Exception("there are doc being save status,please save first!");
            }

            var querySubmit = formContents.Where(x => string.IsNullOrEmpty(x.fnumber));
            int submitCount = await formContentRepository.UpdateListAsync(formContents);

            return(Json(new { isok = true }));
        }
Пример #10
0
        public async Task <FormContent> AddAsync(RaeClassContentType contentType, FormContent formContent)
        {
            FillFormContent(contentType, ref formContent);
            BaseFormContent baseFormContent = GetBaseFormContent(contentType, formContent);

            context.BaseFormContentSet.Add(baseFormContent);
            int res = await context.SaveChangesAsync();

            if (res == 1)
            {
                serialNumberRepository.UpdateMaxIndex(contentType);
                return(formContent);
            }
            else
            {
                return(null);
            }
        }
Пример #11
0
        public Tuple <List <FormContent>, int> GetPageListAsync(RaeClassContentType contentType, string level, string titleOrContent, int pageindex, int pagesize)
        {
            List <FormContent> contents = new List <FormContent>();
            int           pagecount     = 0;
            StringBuilder sb            = new StringBuilder();

            if (contentType != 0)
            {
                sb.AppendFormat(" and FContentType = '{0}' ", contentType);
            }
            if (level.Trim() != "0")
            {
                sb.AppendFormat(" and json_extract(FJsonData,\"$.flevel\") = '{0}' ", level);
            }
            if (!string.IsNullOrEmpty(titleOrContent))
            {
                sb.Append(" and (");
                sb.AppendFormat(" json_extract(FJsonData,\"$.fname\") like '%{0}%' ", titleOrContent);
                sb.Append(" or");
                sb.AppendFormat(" json_extract(FJsonData,\"$.fcnContent\") = '%{0}%' ", titleOrContent);
                sb.Append(" or");
                sb.AppendFormat(" json_extract(FJsonData,\"$.fenContent\") = '%{0}%' ", titleOrContent);
                sb.Append(" )");
            }
            StringBuilder countSb = new StringBuilder();

            countSb.Append("select FId from BaseFormContent where 1=1 ");
            countSb.Append(sb.ToString());
            int count = context.BaseFormContentSet.FromSql(countSb.ToString()).Count();

            if (count >= 0)
            {
                StringBuilder contentSb = new StringBuilder();
                contentSb.Append("select FJsonData from BaseFormContent where 1=1 ");
                contentSb.Append(sb.ToString());
                contentSb.AppendFormat(" limit {0} offset {1} ", pagesize, pageindex);
                List <string> jsonDatas = context.Set <BaseFormContent>().Select(x => x.FJsonData).FromSql(contentSb.ToString()).ToList();
                contents  = JsonHelper.ConvertToModelList <FormContent>(jsonDatas);
                pagecount = count % pagesize == 0 ? count / pagesize : count / pagesize + 1;
            }

            return(new Tuple <List <FormContent>, int>(contents, count));
        }
Пример #12
0
 private void FillFormContents(RaeClassContentType contentType, ref List <FormContent> formContents)
 {
     formContents.ForEach(item => FillFormContent(contentType, ref item));
 }
Пример #13
0
 private void FillFormContent(RaeClassContentType contentType, ref FormContent formContent)
 {
     formContent.fnumber        = serialNumberRepository.GetSerialNumber(contentType);
     formContent.frecordFileId1 = formContent.frecordFileId1;
     formContent.frecordFileId2 = formContent.frecordFileId2;
 }
        public JsonResult Get(RaeClassContentType contentType, string level, string titleOrContent, int pageindex = 1, int pagesize = 10)
        {
            var res = formContentRepository.GetPageListAsync(contentType, level, titleOrContent, pageindex, pagesize);

            return(Json(new { total = res.Item2, rows = res.Item1 }));
        }
 public int GetMaxIndex(RaeClassContentType contentType)
 {
     return(raeClassContext.SerialNumberSet.Where(x => x.FContentType.Equals(contentType.ToString())).FirstOrDefault().FCurrentGeneratedIndex);
 }
        public string GetSerialNumber(RaeClassContentType contentType)
        {
            int maxIndex = GetMaxIndex(contentType) + 1;

            return(contentType.ToString() + CommonUtils.GetDateTimeNowSerial() + maxIndex.ToString());
        }