username@email.com
2022-11-25 d67cb0c9792e23be7ccf655675cb32ac1a236b7b
zhengcaioa/Services/ProjectService.cs
@@ -96,6 +96,12 @@
                    updateproject.Shuliang = project.Shuliang;
                    updateproject.Caigouyusuan = project.Caigouyusuan;
                    if (updateproject.Creater == "111")
                    {
                        updateproject.Creater = project.Modifier;
                        updateproject.Createtime = project.Modifytime;
                    }
                }
                //子表
@@ -128,6 +134,12 @@
                            projectreason.Reasonname = projectDTO.Reasonname[i];
                            projectreason.Reasonremark = projectDTO.Reasonremark[i];
                            projectreason.ProjectId = project.Id;
                            projectreason.WxZhiyistatus = projectDTO.WxZhiyistatus[i];
                            projectreason.WxZhiyishijian = projectDTO.WxZhiyishijian[i];
                            projectreason.WxZhiyichengli = projectDTO.WxZhiyichengli[i];
                            projectreason.WxTousustatus = projectDTO.WxTousustatus[i];
                            projectreason.WxTousushijian = projectDTO.WxTousushijian[i];
                            projectreason.WxTousuchengli = projectDTO.WxTousuchengli[i];
                            _context.Projectreasons.Add(projectreason);
                        } 
                    }
@@ -162,6 +174,13 @@
                            projectyouxiao.Namesyouxiao = projectDTO.Namesyouxiao[i];
                            projectyouxiao.Priceyouxiao = projectDTO.Priceyouxiao[i];
                            projectyouxiao.ProjectId = project.Id;
                            projectyouxiao.YxZhiyistatus = projectDTO.YxZhiyistatus[i];
                            projectyouxiao.YxZhiyishijian = projectDTO.YxZhiyishijian[i];
                            projectyouxiao.YxZhiyichengli = projectDTO.YxZhiyichengli[i];
                            projectyouxiao.YxTousustatus = projectDTO.YxTousustatus[i];
                            projectyouxiao.YxTousushijian = projectDTO.YxTousushijian[i];
                            projectyouxiao.YxTousuchengli = projectDTO.YxTousuchengli[i];
                            _context.Projectyouxiaos.Add(projectyouxiao);
                        }
                    }
@@ -197,6 +216,14 @@
                            projectzhongbiao.Price = projectDTO.Price[i];
                            projectzhongbiao.Defen = projectDTO.Defen[i];
                            projectzhongbiao.ProjectId = project.Id;
                            projectzhongbiao.ZbZhiyistatus = projectDTO.ZbZhiyistatus[i];
                            projectzhongbiao.ZbZhiyishijian = projectDTO.ZbZhiyishijian[i];
                            projectzhongbiao.ZbZhiyichengli = projectDTO.ZbZhiyichengli[i];
                            projectzhongbiao.ZbTousustatus = projectDTO.ZbTousustatus[i];
                            projectzhongbiao.ZbTousushijian = projectDTO.ZbTousushijian[i];
                            projectzhongbiao.ZbTousuchengli = projectDTO.ZbTousuchengli[i];
                            _context.Projectzhongbiaos.Add(projectzhongbiao);
                        }
                    }
@@ -274,7 +301,14 @@
                    projectzhongbiaoDTO.Price = projectzhongbiao.Price;
                    projectzhongbiaoDTO.Defen = projectzhongbiao.Defen;
                     projectzhongbiaoDTOs.Add(projectzhongbiaoDTO);
                    projectzhongbiaoDTO.ZbZhiyichengli = projectzhongbiao.ZbZhiyichengli;
                    projectzhongbiaoDTO.ZbZhiyishijian = projectzhongbiao.ZbZhiyishijian;
                    projectzhongbiaoDTO.ZbZhiyistatus = projectzhongbiao.ZbZhiyistatus;
                    projectzhongbiaoDTO.ZbTousuchengli = projectzhongbiao.ZbTousuchengli;
                    projectzhongbiaoDTO.ZbTousushijian = projectzhongbiao.ZbTousushijian;
                    projectzhongbiaoDTO.ZbTousustatus = projectzhongbiao.ZbTousustatus;
                    projectzhongbiaoDTOs.Add(projectzhongbiaoDTO);
                }
                projectDTO.Projectzhongbiaos = projectzhongbiaoDTOs;
            }
@@ -297,7 +331,7 @@
            List<ProjectDTO> list = new List<ProjectDTO>();
            //筛选
            StringBuilder sql = new StringBuilder();
            sql.Append("SELECT distinct a.[Id],a.[start_time],a.[drhx_defen],a.[caigouyusuan],a.[dshx_defen] ,a.sheng ,a.city  ,a.[area_id],a.cgfs, a.[name] ,a.[number],a.creater,a.createtime,a.modifier,a.modifytime       ,a.[drhx],a.[drhx_price],a.[dshx],a.[dshx_price],a.[Fencha],a.[Shuliang],a.[remark],a.[rec_status] ,a.[question] ,a.[zhongbiaocishu],a.[feibiaocishu],a.[zhongbiaojine],a.[Fblx],a.[Fbyy] , a.[zhuanjia]  , a.[caigourenname], a.[caigourenaddress], a.[caigourencontact], a.[dailiname], a.[dailiaddress], a.[dailicontact] ,'' toubiaocishu   "); //zhuanjia = stuff((select ','+name from [Zhuanjia] f where  CHARINDEX(f.id,a.[zhuanjia]) >0 for xml path('')), 1,1, '')    = stuff((select '、'+ f.[names] from  [Projectzhongbiao] f where  f.[ProjectId] = a.[Id]  for xml path('')), 1,1, '')
            sql.Append("SELECT distinct a.[Id],a.[start_time],a.[drhx_defen],a.[caigouyusuan],a.[dshx_defen] ,a.sheng ,a.city  ,a.[area_id],a.cgfs, a.[name] ,a.[number],a.creater,a.createtime,a.modifier,a.modifytime       ,a.[drhx],a.[drhx_price],a.[dshx],a.[dshx_price],a.[Fencha],a.[Shuliang],a.[remark],a.[rec_status] ,a.[question] ,a.[zhongbiaocishu],a.[feibiaocishu],a.[zhongbiaojine],a.[Fblx],a.[Fbyy] , a.[zhuanjia]  , a.[caigourenname], a.[caigourenaddress], a.[caigourencontact], a.[dailiname], a.[dailiaddress], a.[dailicontact] ,'' toubiaocishu ,a.[dehx_zhiyistatus],a.[dehx_zhiyishijian],a.[dehx_zhiyichengli],a.[dshx_zhiyistatus],a.[dshx_zhiyishijian],a.[dshx_zhiyichengli],a.[dehx_tousustatus],a.[dehx_tousushijian],a.[dehx_tousuchengli],a.[dshx_tousustatus],a.[dshx_tousushijian],a.[dshx_tousuchengli]  "); //zhuanjia = stuff((select ','+name from [Zhuanjia] f where  CHARINDEX(f.id,a.[zhuanjia]) >0 for xml path('')), 1,1, '')    = stuff((select '、'+ f.[names] from  [Projectzhongbiao] f where  f.[ProjectId] = a.[Id]  for xml path('')), 1,1, '')
            sql.Append("FROM [Project] a ");
            //sql.Append("left join  [Area] b  on a.[sheng]  = b.[codeID] ");
            //sql.Append("left join  [Area] c  on a.[city]  = c.[codeID] ");
@@ -435,6 +469,20 @@
               
            }
            if (!string.IsNullOrWhiteSpace(searchEntity.Shifouqueren))
            {
                if (searchEntity.Shifouqueren == "A")
                {
                    sql.Append(" and a.creater  != '111' ");
                }
                else
                {
                    sql.Append(" and a.creater  = '111' ");
                }
            }
            DateTime StartTimestarstart = DateTime.Now;
            DateTime StartTimestarend = DateTime.Now;
@@ -564,21 +612,56 @@
            //}
            if (!string.IsNullOrEmpty(searchEntity.Wanshan))
            {
                if (searchEntity.Wanshan == "A")
                {
                    sql.Append(" and ( a.[drhx] is null or exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[drhx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[drhx] = c.[name] ) ) ");
                    sql.Append(" and ( a.[dshx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[dshx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[dshx] = c.[name] )  ) ");
                    sql.Append(" and  ( a.[caigourenname] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[caigourenname] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[caigourenname] = c.[name] ) )  ");
                    sql.Append(" and ( a.[dailiname] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[dailiname] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[dailiname] = c.[name] ) )  ");
                    sql.Append(" and  (  (select count(b.zhongbiaoId)  from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId] )  = 0  or    ( (select count(b.zhongbiaoId)  from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.zhongbiaoId) from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[names] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[names] = c.[name] )   )))     ");
                    sql.Append(" and  (  (select count(b.youxiaoId)  from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId] )  = 0  or    ( (select count(b.youxiaoId)  from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.youxiaoId) from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[namesyouxiao] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[namesyouxiao] = c.[name] )   )))     ");
                    sql.Append(" and  (  (select count(b.reasonId)  from [Projectreason] b  where  a.[Id]=b.[ProjectId] )  = 0   or    ( (select count(b.reasonId)  from [Projectreason] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.reasonId) from [Projectreason] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[reasonname] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[reasonname] = c.[name] )   )))     ");
                }
                else
                {
                    sql.Append(" and not  ( ( a.[drhx] is null or exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[drhx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[drhx] = c.[name] ) ) ");
                    sql.Append(" and ( a.[dshx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[dshx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[dshx] = c.[name] )  ) ");
                    sql.Append(" and  ( a.[caigourenname] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[caigourenname] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[caigourenname] = c.[name] ) )  ");
                    sql.Append(" and ( a.[dailiname] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[dailiname] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[dailiname] = c.[name] ) )  ");
                    sql.Append(" and  (  (select count(b.zhongbiaoId)  from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId] )  = 0  or    ( (select count(b.zhongbiaoId)  from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.zhongbiaoId) from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[names] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[names] = c.[name] )   )))     ");
                    sql.Append(" and  (  (select count(b.youxiaoId)  from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId] )  = 0  or    ( (select count(b.youxiaoId)  from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.youxiaoId) from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[namesyouxiao] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[namesyouxiao] = c.[name] )   )))     ");
                    sql.Append(" and  (  (select count(b.reasonId)  from [Projectreason] b  where  a.[Id]=b.[ProjectId] )  = 0   or    ( (select count(b.reasonId)  from [Projectreason] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.reasonId) from [Projectreason] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[reasonname] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[reasonname] = c.[name] )   ))) )    ");
                }
            }
            var query = _context.Projects
                var query = _context.Projects
           .FromSqlRaw(sql.ToString()).OrderByDescending(x=>x.StartTime)
           .ToList();
            //if (searchEntity.totalrows == 0)
                searchEntity.totalrows = query.Count();
            searchEntity.totalrows = query.Count();
            var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
            list = _mapper.Map<List<ProjectDTO>>(lianlist);
@@ -620,8 +703,19 @@
                projiectid.Add(projectDTO.Id);
            }
            var projectzhongbiaos = _context.Projectzhongbiaos.Where(x => projiectid.Contains(x.ProjectId)).ToList();
            var projectreasons = _context.Projectreasons.Where(x => projiectid.Contains(x.ProjectId)).ToList();
            var projectyouxiaos = _context.Projectyouxiaos.Where(x => projiectid.Contains(x.ProjectId)).ToList();
            foreach (var projectDTO in list)
            {
                if (projectDTO.DehxZhiyistatus == "A"|| projectDTO.DshxZhiyistatus == "A")
                {
                    projectDTO.Zhiyistatus = "√";
                }
                if (projectDTO.DehxTousustatus == "A" || projectDTO.DshxTousustatus == "A")
                {
                    projectDTO.Tousustatus = "√";
                }
                var ProjectIds = projectzhongbiaos.Where(x => x.ProjectId == projectDTO.Id).ToList();
                projectDTO.Toubiaocishu = "";
                for (int i=0;i< ProjectIds.Count; i++)
@@ -635,7 +729,50 @@
                        projectDTO.Toubiaocishu += ProjectIds[i].Names + "、";
                    }
                    if (ProjectIds[i].ZbZhiyistatus == "A" )
                    {
                        projectDTO.Zhiyistatus = "√";
                    }
                    if (ProjectIds[i].ZbTousustatus == "A")
                    {
                        projectDTO.Tousustatus = "√";
                    }
                }
                var projectreasons1 = projectreasons.Where(x => x.ProjectId == projectDTO.Id).ToList();
                for (int i = 0; i < projectreasons1.Count; i++)
                {
                    if (projectreasons1[i].WxZhiyistatus == "A")
                    {
                        projectDTO.Zhiyistatus = "√";
                    }
                    if (projectreasons1[i].WxZhiyistatus == "A")
                    {
                        projectDTO.Tousustatus = "√";
                    }
                }
                var projectyouxiaos1 = projectyouxiaos.Where(x => x.ProjectId == projectDTO.Id).ToList();
                for (int i = 0; i < projectyouxiaos1.Count; i++)
                {
                    if (projectyouxiaos1[i].YxZhiyistatus == "A")
                    {
                        projectDTO.Zhiyistatus = "√";
                    }
                    if (projectyouxiaos1[i].YxZhiyistatus == "A")
                    {
                        projectDTO.Tousustatus = "√";
                    }
                }
                if (projectDTO.Zhiyistatus != "√")
                {
                    projectDTO.Zhiyistatus = "质疑";
                }
                if (projectDTO.Tousustatus != "√")
                {
                    projectDTO.Tousustatus = "投诉";
                }
            }
@@ -805,5 +942,121 @@
            var list = _mapper.Map<List<ZxdsfxlDTO>>(listPosition);
            return list;
        }
        public ResultEntity savezhiyi(string zhiyistatus, DateTime? zhiyishijian, string zhiyichengli, string projiectid, string mingxiid, string type)
        {
            ResultEntity resultEntity = new ResultEntity();
            try
            {
                if (type == "1")
                {
                    var updateliaotian = _context.Projectzhongbiaos.Find(mingxiid);
                    updateliaotian.ZbZhiyistatus = zhiyistatus;
                    updateliaotian.ZbZhiyishijian = zhiyishijian;
                    updateliaotian.ZbZhiyichengli = zhiyichengli;
                }
                else if (type == "2")
                {
                    var updateliaotian = _context.Projects.Find(projiectid);
                    updateliaotian.DehxZhiyistatus = zhiyistatus;
                    updateliaotian.DehxZhiyishijian = zhiyishijian;
                    updateliaotian.DehxZhiyichengli = zhiyichengli;
                }
                else if (type == "3")
                {
                    var updateliaotian = _context.Projects.Find(projiectid);
                    updateliaotian.DshxZhiyistatus = zhiyistatus;
                    updateliaotian.DshxZhiyishijian = zhiyishijian;
                    updateliaotian.DshxZhiyichengli = zhiyichengli;
                }
                else if (type == "4")
                {
                    var updateliaotian = _context.Projectyouxiaos.Find(mingxiid);
                    updateliaotian.YxZhiyistatus = zhiyistatus;
                    updateliaotian.YxZhiyishijian = zhiyishijian;
                    updateliaotian.YxZhiyichengli = zhiyichengli;
                }
                else if (type == "5")
                {
                    var updateliaotian = _context.Projectreasons.Find(mingxiid);
                    updateliaotian.WxZhiyistatus = zhiyistatus;
                    updateliaotian.WxZhiyishijian = zhiyishijian;
                    updateliaotian.WxZhiyichengli = zhiyichengli;
                }
                _context.SaveChanges();
                resultEntity.ReturnID = projiectid;
                resultEntity.Result = true;
            }
            catch (Exception ex)
            {
                resultEntity.Result = false;
                resultEntity.Message = "保存失败,请联系管理员";
            }
            return resultEntity;
        }
        public ResultEntity savetousu(string tousustatus, DateTime? tousushijian, string tousuchengli, string projiectid, string mingxiid, string type)
        {
            ResultEntity resultEntity = new ResultEntity();
            try
            {
                if (type == "1")
                {
                    var updateliaotian = _context.Projectzhongbiaos.Find(mingxiid);
                    updateliaotian.ZbTousustatus = tousustatus;
                    updateliaotian.ZbTousushijian = tousushijian;
                    updateliaotian.ZbTousuchengli = tousuchengli;
                }
                else if (type == "2")
                {
                    var updateliaotian = _context.Projects.Find(projiectid);
                    updateliaotian.DehxTousustatus = tousustatus;
                    updateliaotian.DehxTousushijian = tousushijian;
                    updateliaotian.DehxTousuchengli = tousuchengli;
                }
                else if (type == "3")
                {
                    var updateliaotian = _context.Projects.Find(projiectid);
                    updateliaotian.DshxTousustatus = tousustatus;
                    updateliaotian.DshxTousushijian = tousushijian;
                    updateliaotian.DshxTousuchengli = tousuchengli;
                }
                else if (type == "4")
                {
                    var updateliaotian = _context.Projectyouxiaos.Find(mingxiid);
                    updateliaotian.YxTousustatus = tousustatus;
                    updateliaotian.YxTousushijian = tousushijian;
                    updateliaotian.YxTousuchengli = tousuchengli;
                }
                else if (type == "5")
                {
                    var updateliaotian = _context.Projectreasons.Find(mingxiid);
                    updateliaotian.WxTousustatus = tousustatus;
                    updateliaotian.WxTousushijian = tousushijian;
                    updateliaotian.WxTousuchengli = tousuchengli;
                }
                _context.SaveChanges();
                resultEntity.ReturnID = projiectid;
                resultEntity.Result = true;
            }
            catch (Exception ex)
            {
                resultEntity.Result = false;
                resultEntity.Message = "保存失败,请联系管理员";
            }
            return resultEntity;
        }
    }
}