username@email.com
2023-10-17 3f4013e9283d1fe29ef40cc8b4d7ee7a590a1590
DocumentServiceAPI.Application/ProjectInfo/Services/ProjectInfoService.cs
@@ -27,6 +27,7 @@
using System.Data;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Reflection.Emit;
using System.Reflection.Metadata;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86;
@@ -614,8 +615,8 @@
            //page.ToEmployeeId = a.EID;
            int total = 0;
            PageResult<DocumentProjectInfoDTO> result = new PageResult<DocumentProjectInfoDTO>();
             //var document_OtherCompanyTenderInfos  =  _db.Queryable<Document_OtherCompanyTenderInfo>().Where(x => x.TenantID == aaa.TEID).ToList();
            result.Items = _db.Queryable<Document_ProjectInfo, Document_ProjectExpand, Document_ProjectOppugnInfo, Document_ProjectComplainInfo, Document_ProjectReviewInfo, Document_ProjectLitigationInfo, Document_AdviseInfo, Document_ProjectComplainInfo, Document_ProjectOppugnInfo, Document_ProjectLitigationInfo, Document_ProjectReviewInfo, Document_WinInfo>((a, d, e,f,g,h,i,j,k,l,m,n) =>
              new JoinQueryInfos
@@ -665,11 +666,11 @@
                     .WhereIF(page.ddlSignUp > 0 && page.ddlSignUp == 1, (a, d, e, f, g, h, i, j, k, l, m, n) => (d.IsSignup == 0 || d.IsSignup == null))
                      .WhereIF(page.ddlSignUp > 0 && page.ddlSignUp != 1, (a, d, e, f, g, h, i, j, k, l, m, n) => d.IsSignup == 1 )
                       //保证金状态
                       .WhereIF(page.ddlTenderDeposit > 0 && page.ddlTenderDeposit == 12, (a, d, e, f, g, h, i, j, k, l, m, n) => d.TenderDepositStatus == null)
                       .WhereIF(page.ddlTenderDeposit > 0 && page.ddlTenderDeposit == 12, (a, d, e, f, g, h, i, j, k, l, m, n) => a.TenderDeposit != null && a.TenderDeposit > 0 && d.TenderDepositStatus == null)
                        .WhereIF(page.ddlTenderDeposit > 0 && page.ddlTenderDeposit == 36, (a, d, e, f, g, h, i, j, k, l, m, n) => a.TenderTime < DateTime.Now.AddDays(15) && d.TenderDepositStatus == 13 )
                      .WhereIF(page.ddlTenderDeposit > 0 && page.ddlTenderDeposit != 12 && page.ddlTenderDeposit != 36, (a, d, e, f, g, h, i, j, k, l, m, n) => d.TenderDepositStatus == page.ddlTenderDeposit)
              //履约金状态
              .WhereIF(page.ddlBidbond > 0 && page.ddlBidbond == 32, (a, d, e, f, g, h, i, j, k, l, m, n) => (d.BidbondStatus == null))
              .WhereIF(page.ddlBidbond > 0 && page.ddlBidbond == 32, (a, d, e, f, g, h, i, j, k, l, m, n) => (a.Bidbond!=null && a.Bidbond >0 && d.BidbondStatus == null))
                      .WhereIF(page.ddlBidbond > 0 && page.ddlBidbond != 32, (a, d, e, f, g, h, i, j, k, l, m, n) => d.BidbondStatus == page.ddlBidbond )
               //标书状态
               .WhereIF(page.ddlDocumentStatus > 0 && page.ddlDocumentStatus == 15, (a, d, e, f, g, h, i, j, k, l, m, n) => (d.DocumentStatus == null || d.DocumentStatus == 0 || d.DocumentStatus == 15))
@@ -692,6 +693,9 @@
               //诉讼情况
               .WhereIF(page.ddlLitigationStatus > 0 && page.ddlLitigationStatus == 1, (a, d, e, f, g, h, i, j, k, l, m, n) => (h.FilePath == null || h.FilePath == ""))
                      .WhereIF(page.ddlLitigationStatus > 0 && page.ddlLitigationStatus != 1, (a, d, e, f, g, h, i, j, k, l, m, n) => (h.FilePath != null && h.FilePath != ""))
               .WhereIF(!string.IsNullOrEmpty(page.txtCompanyName), (a, d, e, f, g, h, i, j, k, l, m, n) => (n.FirstWinCompany.Contains(page.txtCompanyName) || n.SecondWinCompany.Contains(page.txtCompanyName) || n.ThirdCompany.Contains(page.txtCompanyName) || SqlFunc.Subqueryable<Document_OtherCompanyTenderInfo>().Where(s => s.TenantID == a.TenantID && s.ProjectId == a.ProjectId && s.CompanyName.Contains(page.txtCompanyName)).Any()))
             .Select((a, d, e, f, g, h, i, j, k, l, m, n) => new DocumentProjectInfoDTO
             {
                 ProjectId = a.ProjectId,
@@ -719,7 +723,9 @@
                 NoticeTypeName = "招标公告",
                 NoticeType = a.NoticeType,
                 PurchaseMethod = a.PurchaseMethod,
                 DocumentStatus = d.DocumentStatus
                 DocumentStatus = d.DocumentStatus,
                 SignupMethod = a.SignupMethod,
             }
              )
             .OrderByDescending(a => a.ProjectId).ToPageList(page.PageIndex, page.PageSize, ref total);
@@ -746,7 +752,7 @@
                        documentProjectInfoDTO.xmqy = documentProjectInfoDTO.City+ documentProjectInfoDTO.County;
                    }
                    if(documentProjectInfoDTO.IsSignup == 1)
                    if(documentProjectInfoDTO.IsSignup == 1 || documentProjectInfoDTO.SignupMethod == 9   )
                    {
                        documentProjectInfoDTO.bm = "√";
                    }
@@ -871,7 +877,18 @@
                            documentProjectInfoDTO.PurchaseMethodName = document_Dictionary.Name;
                        }
                    }
                    var sss = _db.Queryable<Document_ZhaobiaoFile>().Count(x => x.ProjectId == documentProjectInfoDTO.ProjectId && x.UnitId == page.UnitId);
                    if (sss > 0)
                    {
                        documentProjectInfoDTO.zbwj = "√";
                    }
                    else
                    {
                        documentProjectInfoDTO.zbwj = "招标文件";
                    }
                }
            }
@@ -1642,7 +1659,7 @@
        public PageResult<Document_TBXYFile> postDocumentTBXYFileList(DocumentProjectInfoPageSearch page)
        public PageResult<DocumentTBXYFileDTO> postDocumentTBXYFileList(DocumentProjectInfoPageSearch page)
        {
            var aaa = GetJwtInfo();
@@ -1651,7 +1668,7 @@
            pg.PageIndex = page.PageIndex;
            //page.ToEmployeeId = a.EID;
            int total = 0;
            PageResult<Document_TBXYFile> result = new PageResult<Document_TBXYFile>();
            PageResult<DocumentTBXYFileDTO> result = new PageResult<DocumentTBXYFileDTO>();
@@ -1659,8 +1676,10 @@
                .Where(a => a.UnitId == page.UnitId && a.ProjectId == page.ProjectId)
             //文件名称
             .WhereIF(!string.IsNullOrEmpty(page.FileName), a => a.FileName.Contains(page.FileName))
                .WhereIF(page.Classification>0, a => a.Classification == page.Classification)
                   .WhereIF(!string.IsNullOrEmpty(page.FilePath), a => ( a.FilePath !=null && a.FilePath != ""))
             .Select(a => new Document_TBXYFile
             .Select(a => new DocumentTBXYFileDTO
             {
                 Id = a.Id,
                 FileName = a.FileName,
@@ -1673,11 +1692,24 @@
                 AdviseFlag = a.AdviseFlag,
                 UserId = a.UserId,
                 Sort = a.Sort,
                 Classification = a.Classification,
             }
              )
             .OrderBy(a => a.Sort).ToPageList(page.PageIndex, page.PageSize, ref total);
            if(result.Items !=null&& result.Items.Count > 0)
            {
                var doc_Classifications = _db.Queryable<Doc_Classification>().Where(x => x.parent_code == "003").ToList();//执行查询
                foreach (var item in result.Items)
                {
                    var doc_Classification = doc_Classifications.Where(x => x.id == item.Classification).FirstOrDefault();
                    if (doc_Classification != null)
                    {
                        item.ClassificationName = doc_Classification.doc_classification;
                    }
                }
            }
            result.TotalCount = total;
            result.TotalPage = total % page.PageSize == 0 ? total / page.PageSize : total / page.PageSize + 1;
@@ -1745,7 +1777,7 @@
                UserId = a.UserId,
                Sort = a.Sort,
                    SaveFlag = a.SaveFlag,
                    Classification  = a.Classification,
                }).OrderBy(a => a.Sort).ToList();
            return ret;
        }
@@ -1785,5 +1817,297 @@
            return true;
        }
        public List<Doc_Classification> GetDocClassificationList()
        {
            var ret = _db.Queryable<Doc_Classification>().Where(x => x.parent_code =="003"  && x.is_system == true).ToList();
            return ret;
        }
        public bool SaveDocumentTBXYFileInfoNotRep(Document_TBXYFile dp)
        {
            if (dp.Id > 0)
            {
                _db.Updateable<Document_TBXYFile>(dp).ExecuteCommand();
            }
            else
            {
                _db.Insertable<Document_TBXYFile>(dp).ExecuteCommand();
            }
            return true;
        }
        public PageResult<DocClassificationDTO> postDocClassificationList(DocumentProjectInfoPageSearch page)
        {
            var aaa = GetJwtInfo();
            SqlSugar.PageModel pg = new SqlSugar.PageModel();
            pg.PageSize = page.PageSize;
            pg.PageIndex = page.PageIndex;
            //page.ToEmployeeId = a.EID;
            int total = 0;
            PageResult<DocClassificationDTO> result = new PageResult<DocClassificationDTO>();
            result.Items = _db.Queryable<Doc_Classification, Doc_ClassDel>((a, b) =>
              new JoinQueryInfos
              (
             JoinType.Left, a.id == b.doc_classification_id && b.tenant_code == page.TenantID
                  ))
                .Where((a, b) => ( a.tenant_code == page.TenantID || a.is_system == true) )
             //文件名称
             .WhereIF(!string.IsNullOrEmpty(page.FileName), (a, b) => a.doc_classification.Contains(page.FileName))
               .WhereIF(!string.IsNullOrEmpty(page.parentcode), (a, b) => a.parent_code == page.parentcode )
                  .WhereIF(page.Status.HasValue, (a, b) => (a.is_system == false && a.status == page.Status.Value ) || (page.Status.Value == 1 && a.is_system == true && b.tenant_code == null ) || (page.Status.Value == 0 && a.is_system == true && b.tenant_code != null))
             .Select((a, b) => new DocClassificationDTO
             {
                 id = a.id,
                 doc_classification_code = a.doc_classification_code,
                 doc_classification = a.doc_classification,
                 parent_code = a.parent_code,
                 is_system = a.is_system,
                 sort_id = a.sort_id,
                 tenant_code = a.tenant_code,
                 add_time = a.add_time,
                 status = a.status,
             }
              )
             .OrderBy(a => a.sort_id).ToPageList(page.PageIndex, page.PageSize, ref total);
            if (result.Items != null && result.Items.Count > 0)
            {
                foreach (var item in result.Items)
                {
                    if (item.is_system)
                    {
                        var doc_ClassDel = _db.Queryable<Doc_ClassDel>().Where(x => x.doc_classification_id == item.id && x.tenant_code == page.TenantID ).First();//执行查询
                        if (doc_ClassDel != null)
                        {
                            item.status = 0;
                            item.statusName = "停用";
                        }
                        else
                        {
                            item.statusName = "启用";
                        }
                    }
                    else
                    {
                        if(item.status == 1)
                        {
                            item.statusName = "启用";
                        }
                        else
                        {
                            item.statusName = "停用";
                        }
                    }
                }
            }
            result.TotalCount = total;
            result.TotalPage = total % page.PageSize == 0 ? total / page.PageSize : total / page.PageSize + 1;
            return result;
        }
        public Doc_Classification GetDocClassificationInfo(int ID)
        {
            var aaa = GetJwtInfo();
            var result = _db.Queryable<Doc_Classification>().Where(x => x.id == ID).First();//执行查询
            if (result!=null && result.is_system)
            {
                var doc_ClassDel = _db.Queryable<Doc_ClassDel>().Where(x => x.doc_classification_id == result.id && x.tenant_code == aaa.TEID).First();//执行查询
                if (doc_ClassDel != null)
                {
                    result.status = 0;
                }
                else
                {
                    result.status = 1;
                }
            }
            return result;
        }
        public bool GetDeleteDocClassDel(int ID , int tenantId)
        {
            _db.Deleteable<Doc_ClassDel>().Where(x => x.doc_classification_id == ID &&  x.tenant_code == tenantId ).ExecuteCommand();
            return true;
        }
        public bool GetDeleteDocClassification(int ID )
        {
            var result = _db.Queryable<Doc_Classification>().Where(x => x.id == ID).First();//执行查询
            if (result != null)
            {
                _db.Deleteable<Doc_Classification>().Where(x => x.parent_code == result.doc_classification_code).ExecuteCommand();
            }
            _db.Deleteable<Doc_Classification>().Where(x => x.id == ID ).ExecuteCommand();
            return true;
        }
        public bool SaveDocClassificationInfo(Doc_Classification dp)
        {
            if (dp.id > 0)
            {
                _db.Updateable<Doc_Classification>(dp).ExecuteCommand();
            }
            else
            {
                _db.Insertable<Doc_Classification>(dp).ExecuteCommand();
            }
            return true;
        }
        public bool SaveDocClassDelInfo(Doc_ClassDel dp)
        {
            if (dp.id > 0)
            {
                _db.Updateable<Doc_ClassDel>(dp).ExecuteCommand();
            }
            else
            {
                _db.Insertable<Doc_ClassDel>(dp).ExecuteCommand();
            }
            return true;
        }
        public List<Doc_Classification> GetDocClassificationList(int tenantId)
        {
            var ret = _db.Queryable<Doc_Classification>()
                .Where(x => ((x.tenant_code == tenantId && x.status == 1) || x.is_system == true) && x.parent_code == "00" )
                //.Select(a => new Document_TBXYFile
                //{
                //    Id = a.Id,
                //    FileName = a.FileName,
                //    FilePath = a.FilePath,
                //    FileVersionNo = a.FileVersionNo,
                //    FileSize = a.FileSize,
                //    UnitId = a.UnitId,
                //    LastUpdateTime = a.LastUpdateTime,
                //    LastUpdateName = a.LastUpdateName,
                //    AdviseFlag = a.AdviseFlag,
                //    UserId = a.UserId,
                //    Sort = a.Sort,
                //    SaveFlag = a.SaveFlag,
                //    Classification = a.Classification,
                //})
                .OrderBy(a => a.sort_id).ToList();
            if (ret != null && ret.Count > 0)
            {
                foreach (var item in ret)
                {
                    if (item.is_system)
                    {
                        var doc_ClassDel = _db.Queryable<Doc_ClassDel>().Where(x => x.doc_classification_id == item.id && x.tenant_code == tenantId).First();//执行查询
                        if (doc_ClassDel != null)
                        {
                            item.status = 0;
                        }
                    }
                }
            }
            ret = ret.Where(x => x.status == 1).ToList();
            return ret;
        }
        public Doc_Classification GetDocClassificationByFileName(int tenantId , string FileName, string parent_code)
        {
            var ret = _db.Queryable<Doc_Classification>().Where(x => ( x.tenant_code == tenantId || x.is_system == true  ) && x.doc_classification == FileName && x.parent_code ==  parent_code).First();
            return ret;
        }
        public Doc_Classification GetDocClassificationcode(int tenantId,string parent_code)
        {
            var ret = _db.Queryable<Doc_Classification>().Where(x => (x.tenant_code == tenantId || x.is_system == true)  && x.parent_code == parent_code).OrderByDescending(x=>x.doc_classification_code).First();
            string doc_classification_code = (int.Parse(ret.doc_classification_code) + 1).ToString().PadLeft(3, '0');
            Doc_Classification doc_Classification = new Doc_Classification();
            doc_Classification.doc_classification_code = doc_classification_code;
            return doc_Classification;
        }
        public Doc_Classification GetDocClassificationInfoMaxSortId(int tenantId ,string docclassificationcode)
        {
            var ret = _db.Queryable<Doc_Classification>()
                .Where(x => (x.tenant_code == tenantId || x.is_system == true))
                .WhereIF(!string.IsNullOrEmpty(docclassificationcode), x => x.parent_code == docclassificationcode)
                .Where(x => x.sort_id <= 99999)
                .Max(x => x.sort_id);
            Doc_Classification doc_Classification = new Doc_Classification();
            doc_Classification.sort_id = ret;
            return doc_Classification;
        }
        public Doc_Classification GetDocumentInfoMaxSortId(int unitId, string doccode)
        {
            var ret = _db.Queryable<Doc_Info>()
                .Where(x => x.org_id == unitId )
                .WhereIF(!string.IsNullOrEmpty(doccode), x => x.doc_code == doccode)
                .Max(x => x.sort);
            Doc_Classification doc_Classification = new Doc_Classification();
            doc_Classification.sort_id = ret??0;
            return doc_Classification;
        }
        public Doc_Classification GetAchievementInfoMaxSortId(int unitId)
        {
            var ret = _db.Queryable<Doc_Achievement>()
              .Where(x => x.tenant_code == unitId)
            //.WhereIF(!string.IsNullOrEmpty(doccode), x => x.doc_code == doccode)
            .Max(x => x.sort);
            Doc_Classification doc_Classification = new Doc_Classification();
            doc_Classification.sort_id = ret ?? 0;
            return doc_Classification;
        }
    }
}