public async Task<ActionResult> OverallSummary(OverallSummaryViewModel viewModel, BasicSurveyReportViewModel paramModel)
        {
            ViewBag.LeftMenu = Global.Report;
            var comments = await rptMentorCommentService.GetRptMentorCommentListAsync(paramModel.QuestionSn, paramModel.BizWorkSn, paramModel.BizWorkYear, "04");

            foreach(var item in viewModel.CommentList)
            {
                var comment = comments.SingleOrDefault(i => i.DetailCd == item.DetailCd);
                if(comment == null)
                {
                    rptMentorCommentService.Insert(ReportHelper.MakeRptMentorcomment(item, paramModel));
                }
                else
                {
                    comment.Comment = item.Comment;
                }
            }

            await rptMentorCommentService.SaveDbContextAsync();

            if (viewModel.SubmitType == "T")
            {
                return RedirectToAction("OverallSummary", "BasicSurveyReport", new { BizWorkSn = paramModel.BizWorkSn, CompSn = paramModel.CompSn, BizWorkYear = paramModel.BizWorkYear, Status = paramModel.Status, QuestionSn = paramModel.QuestionSn });
            }
            else
            {
                return RedirectToAction("OverallResultCover", "BasicSurveyReport", new { BizWorkSn = paramModel.BizWorkSn, CompSn = paramModel.CompSn, BizWorkYear = paramModel.BizWorkYear, Status = paramModel.Status, QuestionSn = paramModel.QuestionSn });
            }
        }
        public async Task<ActionResult> OverallSummary(BasicSurveyReportViewModel paramModel)
        {
            ViewBag.LeftMenu = Global.Report;

            //double totalPoint = 0;
            OverallSummaryViewModel viewModel = new OverallSummaryViewModel();
            viewModel.CommentList = new List<CommentViewModel>();
            ReportUtil reportUtil = new ReportUtil(scBizWorkService, quesResult1Service, quesResult2Service, quesMasterService, sboFinancialIndexTService);

            //해당기업 기초역량
            double basicCapa = 0.0;
            //해당기업 기술경영 마케팅관리
            double mkt = 0.0;
            //해당기업 인적자원관리
            double hrMng = 0.0;
            //해당기업 1인당 노동생산성
            double workProductivity = 0.0;
            //해당기업 매출영업이익률
            double salesEarning = 0.0;
            //해당기업 유동비율
            double current = 0.0;


            //1) 현재 사업에 참여한 업체 평균
            var curBizWork = await scBizWorkService.GetBizWorkByBizWorkSn(paramModel.BizWorkSn);

            //인적자원관리
            Dictionary<string, double> dicBizInHrMng = new Dictionary<string, double>();
            //기술경영마케팅
            Dictionary<string, double> dicBizInMkt = new Dictionary<string, double>();
            //기초역량
            Dictionary<string, double> dicBizInBasicCpas = new Dictionary<string, double>();
            //매출액
            Dictionary<string, decimal> dicSales = new Dictionary<string, decimal>();
            //재료비
            Dictionary<string, decimal> dicMaterrial = new Dictionary<string, decimal>();
            //종업원수
            Dictionary<string, decimal> dicQtEmp = new Dictionary<string, decimal>();
            //영업이익
            Dictionary<string, decimal> dicOperatingErning = new Dictionary<string, decimal>();
            //유동자산
            Dictionary<string, decimal> dicCurrentAsset = new Dictionary<string, decimal>();
            //유동부채
            Dictionary<string, decimal> dicCurrentLiability = new Dictionary<string, decimal>();

            {
                var compMappings = curBizWork.ScCompMappings;
                foreach (var compMapping in compMappings)
                {
                    //문진표 작성내역 조회
                    var quesMaster = await quesMasterService.GetQuesMasterAsync(compMapping.ScCompInfo.RegistrationNo, paramModel.BizWorkYear);
                    if (quesMaster == null)
                    {
                        continue;
                    }
                    //다래 재무정보 조회해야 함.
                    var sboFinacialIndexT = await sboFinancialIndexTService.GetSHUSER_SboFinancialIndexT(compMapping.ScCompInfo.RegistrationNo, ConfigurationManager.AppSettings["CorpCode"], ConfigurationManager.AppSettings["BizCode"], paramModel.BizWorkYear.ToString());
                    if (sboFinacialIndexT == null)
                    {
                        continue;
                    }


                    //참여기업의 점수 계산
                    var bizInHrMng = await reportUtil.GetHumanResourceMng(quesMaster.QuestionSn, sboFinacialIndexT);
                    var bizInMkt = await reportUtil.GetTechMng(quesMaster.QuestionSn, sboFinacialIndexT);
                    var bizInBasicCapa = await reportUtil.GetOverAllManagementTotalPoint(quesMaster.QuestionSn);

                    //해당기업을 찾아 점수를 별도로 저장한다.
                    if (quesMaster.QuestionSn == paramModel.QuestionSn)
                    {
                        basicCapa = bizInBasicCapa;
                        mkt = bizInMkt;
                        hrMng = bizInHrMng;

                        if (sboFinacialIndexT.QtEmp != 0)
                        {
                            workProductivity = Math.Truncate(Convert.ToDouble(((sboFinacialIndexT.CurrentSale - sboFinacialIndexT.MaterialCost) / sboFinacialIndexT.QtEmp) / 1000));
                        }

                        if (sboFinacialIndexT.CurrentSale != 0)
                        {
                            salesEarning = Math.Round(Convert.ToDouble((sboFinacialIndexT.OperatingEarning / sboFinacialIndexT.CurrentSale) * 100), 1);
                        }

                        if (sboFinacialIndexT.CurrentLiability != 0)
                        {
                            current = Math.Round(Convert.ToDouble((sboFinacialIndexT.CurrentAsset / sboFinacialIndexT.CurrentLiability) * 100), 1);
                        }


                        dicBizInHrMng.Add(compMapping.ScCompInfo.RegistrationNo, bizInHrMng);
                        dicBizInMkt.Add(compMapping.ScCompInfo.RegistrationNo, bizInMkt);
                        dicBizInBasicCpas.Add(compMapping.ScCompInfo.RegistrationNo, bizInBasicCapa);

                        dicSales.Add(compMapping.ScCompInfo.RegistrationNo, sboFinacialIndexT.CurrentSale.Value);
                        dicMaterrial.Add(compMapping.ScCompInfo.RegistrationNo, sboFinacialIndexT.MaterialCost.Value);
                        dicQtEmp.Add(compMapping.ScCompInfo.RegistrationNo, sboFinacialIndexT.QtEmp.Value);
                        dicOperatingErning.Add(compMapping.ScCompInfo.RegistrationNo, sboFinacialIndexT.OperatingEarning.Value);
                        dicCurrentAsset.Add(compMapping.ScCompInfo.RegistrationNo, sboFinacialIndexT.CurrentAsset.Value);
                        dicCurrentLiability.Add(compMapping.ScCompInfo.RegistrationNo, sboFinacialIndexT.CurrentLiability.Value);
                    }

                }
            }

            // 3) 기초자료 전체 평균
            // 설명자료에 해당 내용 없음.

            // 4) 전체 평균정수 계산
            double totalPoint = 0;
            totalPoint = totalPoint + dicBizInHrMng.Values.Sum();
            totalPoint = totalPoint + dicBizInMkt.Values.Sum();
            totalPoint = totalPoint + dicBizInBasicCpas.Values.Sum();
            viewModel.AvgTotalPoint = (dicBizInHrMng.Count == 0) ? 0 : Math.Round(totalPoint / dicBizInHrMng.Count, 1);

            //1-B. 해당 기업의 기초역량 점수 계산
            double companyPoint = 0;
            companyPoint = basicCapa + mkt + hrMng;
            viewModel.CompanyPoint = Math.Round(companyPoint, 1);

            //2. 경영역량 총괄 화살표
            viewModel.BizCapaType = ReportHelper.GetArrowTypeA(companyPoint);

            //3. 인적자원관리 화살표(해당기업)
            viewModel.HRMngType = ReportHelper.GetArrowTypeB(hrMng);

            //4. 기술경영, 마케팅 화살표(해당기업)
            viewModel.MarketingType = ReportHelper.GetArrowTypeC(mkt);

            //5. 기초역량 화살표(해당기업)
            viewModel.BasicCapaType = ReportHelper.GetArrowTypeD(basicCapa);

            //6. 조직문화도 화살표  -------------> 해당 페이지 개발 후 적용 해야함.
            var orgDivided = await rptMentorCommentService.GetRptMentorCommentAsync(paramModel.QuestionSn, paramModel.BizWorkSn, paramModel.BizWorkYear, "02030901");

            if(orgDivided != null)
            { 
                viewModel.OrgType = ReportHelper.GetArrowTypeE(int.Parse(orgDivided.Comment));
            }
            else
            {
                viewModel.OrgType = "C";
            }
            //7. 고객의수, 상품의질 화살표 -------------> 해당 페이지 개발 후 적용 해야함.
            var custMng = await rptMentorCommentService.GetRptMentorCommentAsync(paramModel.QuestionSn, paramModel.BizWorkSn, paramModel.BizWorkYear, "02022112");
            if (custMng != null)
            {
                viewModel.CustMngType = ReportHelper.GetArrowTypeE(int.Parse(custMng.Comment));
            }
            else
            {
                viewModel.CustMngType = "C";
            }
            //8. 전반적 제도 및 규정관리체계 화살표 -------------> 해당 페이지 개발 후 적용 해야함.02033128
            var rool = await rptMentorCommentService.GetRptMentorCommentAsync(paramModel.QuestionSn, paramModel.BizWorkSn, paramModel.BizWorkYear, "02033128");

            if (rool != null)
            {
                viewModel.RoolType = ReportHelper.GetArrowTypeE(int.Parse(rool.Comment));
            }
            else
            {
                viewModel.RoolType = "C";
            }

            //9. 조직역량-인적자원관리 해당기업 점수
            OverallSummaryPointViewModel orgCapa = new OverallSummaryPointViewModel();
            orgCapa.CompanyPoint = Math.Round(hrMng, 1);
            //12. 조직역량-인적자원관리 참여기업 평균 점수
            orgCapa.AvgBizInCompanyPoint = Math.Round(dicBizInHrMng.Values.Average(), 1);
            //15. 조직역량-인적자원관리 전체평균 점수
            orgCapa.AvgTotalPoint = Math.Round((dicBizInHrMng.Values.Sum()+ 277.75)/(dicBizInHrMng.Count + 39), 1);
            //18. 조직역량-1인당노동생산성 해당기업점수
            orgCapa.CompanyPoint2 = workProductivity;
            //21. 조직역량-1인당노동생산성 참여기업 평균
            orgCapa.AvgBizInCompanyPoint2 = (dicQtEmp.Values.Sum() == 0) ? 0 : Math.Truncate(Convert.ToDouble(((dicSales.Values.Sum() - dicMaterrial.Values.Sum()) / dicQtEmp.Values.Sum()) / 1000));
            //24. 조직역량-1인당노동생산성 전체 평균
            orgCapa.AvgTotalPoint2 = Math.Truncate(Convert.ToDouble((((dicSales.Values.Sum() + 111710064106) - (dicMaterrial.Values.Sum() + 43571068769)) / (dicQtEmp.Values.Sum() + 718 )) / 1000));
            //27. 조직역량-1인당노동생산성 중소기업평균
            orgCapa.AvgSMCompanyPoint = 64342;
            viewModel.OrgCapa = orgCapa;

            //10. 상품화역량-기술경영 마케팅관리 해당기업 점수
            OverallSummaryPointViewModel prductionCapa = new OverallSummaryPointViewModel();
            prductionCapa.CompanyPoint = Math.Round(mkt, 1);
            //13. 상품화역량-기술경영 마케팅관리 참여기업 평균 점수
            prductionCapa.AvgBizInCompanyPoint = Math.Round(dicBizInMkt.Values.Average(), 1);
            //16. 상품화역량-기술경영 마케팅관리 전체평균 점수
            prductionCapa.AvgTotalPoint = Math.Round((dicBizInMkt.Values.Sum() + 770.25) / (dicBizInMkt.Count + 39), 1);
            //19. 상품화역량-매출영업이익률 해당기업 점수
            prductionCapa.CompanyPoint2 = salesEarning;
            //22. 상품화역량-매출영업이익률 참여기업 평균
            prductionCapa.AvgBizInCompanyPoint2 = (dicSales.Values.Sum() == 0) ? 0 : Math.Round(Convert.ToDouble((dicOperatingErning.Values.Sum() / dicSales.Values.Sum()) * 100), 1);
            //25. 상품화역량-매출영업이익률 전체평균
            prductionCapa.AvgTotalPoint2 = Math.Round(Convert.ToDouble(((dicOperatingErning.Values.Sum() + 6689265895) / (dicSales.Values.Sum() + 111710064106)) * 100), 1);
            //28. 상품화역량-매출영업이익률 중소기업평균
            prductionCapa.AvgSMCompanyPoint = 5.2;
            viewModel.ProductionCapa = prductionCapa;

            //11. 위험관리역량-기초역량 해당기업 점수
            OverallSummaryPointViewModel riskMngCapa = new OverallSummaryPointViewModel();
            riskMngCapa.CompanyPoint = Math.Round(basicCapa, 1);
            //14. 위험관리역량-기초역량 참여기업 평균 점수
            riskMngCapa.AvgBizInCompanyPoint = Math.Round(dicBizInBasicCpas.Values.Average(), 1);
            //17. 위험관리역량-기초역량 전체평균 점수
            riskMngCapa.AvgTotalPoint = Math.Round((dicBizInBasicCpas.Values.Sum() + 238.38) / (dicBizInBasicCpas.Count + 39), 1);
            //20. 위험관리역량-유동비율 해당기업 점수
            riskMngCapa.CompanyPoint2 = current;
            //23. 위험관리역량-유동비율 참여기업평균 점수
            riskMngCapa.AvgBizInCompanyPoint2 = (dicCurrentLiability.Values.Sum() == 0) ? 0 : Math.Round(Convert.ToDouble((dicCurrentAsset.Values.Sum() / dicCurrentLiability.Values.Sum()) * 100), 1);
            //26. 위험관리역량-유동비율 전체평균 점수
            riskMngCapa.AvgTotalPoint2 = Math.Round(Convert.ToDouble(((dicCurrentAsset.Values.Sum() + 58220981909) / (dicCurrentLiability.Values.Sum() + 23152799577)) * 100), 1);
            //29. 위험관리역량-유동비율 중소기업평균 점수
            riskMngCapa.AvgSMCompanyPoint = 136.3;
            viewModel.RiskMngCapa = riskMngCapa;

            //멘토 작성내용 조회
            var comments = await rptMentorCommentService.GetRptMentorCommentListAsync(paramModel.QuestionSn, paramModel.BizWorkSn, paramModel.BizWorkYear, "04");
            //조직역량->조직분화도
            var comment0 = comments.SingleOrDefault(i => i.DetailCd == "01010401");
            viewModel.CommentList.Add(ReportHelper.MakeCommentViewModel(paramModel, "01010401", comment0));

            // 상품화역량 -> 고객의수, 상품의 질 및 마케팅 수준
            var comment1 = comments.SingleOrDefault(i => i.DetailCd == "01010402");
            viewModel.CommentList.Add(ReportHelper.MakeCommentViewModel(paramModel, "01010402", comment1));

            // 위험관리역량 -> 제무회계 관리체계 및 제도수준
            var comment2 = comments.SingleOrDefault(i => i.DetailCd == "01010403");
            viewModel.CommentList.Add(ReportHelper.MakeCommentViewModel(paramModel, "01010403", comment2));

            ViewBag.paramModel = paramModel;
            return View(viewModel);

        }