コード例 #1
0
ファイル: CompanyOrderService.cs プロジェクト: junlu3/CMS
        public void ExportHealthCareRecords(string filePath, CompanyEmployee emp)
        {
            var baseRowTemplateIndex_Table2 = 21;
            var baseRowTemplateIndex_Table3 = 26;
            var baseRowTemplateIndex_Table4 = 31;
            var baseRowTemplateIndex_Table5 = 46;
            var totalMoveRowCount           = 0;

            var excelModel = new ExcelModel();

            var excelSheet = new ExcelSheetModel();

            excelSheet.Name = "Sheet1";

            #region 封面

            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "编号",
                RowIndex    = 1,
                ColumnIndex = 16,
                Value       = DateTime.Now.ToString("yyyyMMddhhmmss"),
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "区县",
                RowIndex    = 2,
                ColumnIndex = 16,
                Value       = "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "姓名",
                RowIndex    = 7,
                ColumnIndex = 7,
                Value       = emp.EmployeeBaseInfo.UserName,
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "单位名称",
                RowIndex    = 8,
                ColumnIndex = 7,
                Value       = emp.Company.CompanyName,
            });

            #endregion

            #region 基本信息

            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "工号",
                RowIndex    = 12,
                ColumnIndex = 2,
                Value       = emp.WorkNumber,
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "岗位状态",
                RowIndex    = 12,
                ColumnIndex = 9,
                Value       = emp.WorkType
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "上岗时间",
                RowIndex    = 12,
                ColumnIndex = 15,
                Value       = emp.StartPostDate.HasValue ? emp.StartPostDate.Value.ToString("yyyy/MM") : "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "离岗时间",
                RowIndex    = 12,
                ColumnIndex = 17,
                Value       = emp.EndPostDate.HasValue ? emp.EndPostDate.Value.ToString("yyyy/MM") : "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "姓名",
                RowIndex    = 13,
                ColumnIndex = 2,
                Value       = emp.EmployeeBaseInfo.UserName,
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "身份证",
                RowIndex    = 13,
                ColumnIndex = 9,
                Value       = emp.EmployeeBaseInfo.IDCard,
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "性别",
                RowIndex    = 13,
                ColumnIndex = 15,
                Value       = emp.EmployeeBaseInfo.Sex,
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "是否需离岗体检",
                RowIndex    = 13,
                ColumnIndex = 17,
                Value       = "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "出生年月",
                RowIndex    = 14,
                ColumnIndex = 2,
                Value       = IDCardHelper.GetBirthDay(emp.EmployeeBaseInfo.IDCard).ToString("yyyy年MM月"),
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "户籍",
                RowIndex    = 14,
                ColumnIndex = 9,
                Value       = "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "是否已体检",
                RowIndex    = 14,
                ColumnIndex = 17,
                Value       = "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "文化程度",
                RowIndex    = 15,
                ColumnIndex = 2,
                Value       = "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "是否吸烟",
                RowIndex    = 15,
                ColumnIndex = 9,
                Value       = "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "个人爱好",
                RowIndex    = 16,
                ColumnIndex = 2,
                Value       = "",
            });
            excelSheet.Cells.Add(new ExcelSheetCellModel()
            {
                Title       = "既往史",
                RowIndex    = 17,
                ColumnIndex = 2,
                Value       = "",
            });

            #endregion

            #region 职业史

            if (emp.EmployeeBaseInfo.WorkHistories.Count > 0)
            {
                for (int i = 0; i < emp.EmployeeBaseInfo.WorkHistories.Count; i++)
                {
                    var item     = emp.EmployeeBaseInfo.WorkHistories[i];
                    var rowIndex = baseRowTemplateIndex_Table2 + i + 1;

                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title            = "用人单位名称",
                        RowIndex         = rowIndex,
                        ColumnIndex      = 1,
                        Value            = item.CompanyName,
                        TemplateRowIndex = baseRowTemplateIndex_Table2
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "从事工种",
                        RowIndex    = rowIndex,
                        ColumnIndex = 3,
                        Value       = item.WorkType,
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "工作岗位",
                        RowIndex    = rowIndex,
                        ColumnIndex = 6,
                        Value       = item.Department,
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "起始时间",
                        RowIndex    = rowIndex,
                        ColumnIndex = 8,
                        Value       = string.Format("{0} - {1}", item.EntryDate.HasValue ? item.EntryDate.Value.ToString("yyyy年MM月") : "", item.LeaveDate.HasValue ? item.LeaveDate.Value.ToString("yyyy年MM月") : "")
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "是否危害岗位",
                        RowIndex    = rowIndex,
                        ColumnIndex = 14,
                        Value       = string.IsNullOrEmpty(item.AdverseFactor) ? "否" : "是",
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "接触职业危害因素名称1",
                        RowIndex    = rowIndex,
                        ColumnIndex = 15,
                        Value       = item.AdverseFactor,
                    });
                }

                totalMoveRowCount += emp.EmployeeBaseInfo.WorkHistories.Count;
            }

            #endregion

            #region 职业危害接触史

            baseRowTemplateIndex_Table3 += totalMoveRowCount;
            totalMoveRowCount           += 0;

            #endregion

            #region 职业卫生(健康)检查结果

            baseRowTemplateIndex_Table4 += totalMoveRowCount;
            var healthResultList = _healthResultRepository.GetByIDCard(emp.EmployeeBaseInfo.IDCard);
            if (healthResultList.Count > 0)
            {
                for (int i = 0; i < healthResultList.Count; i++)
                {
                    var item     = healthResultList[i];
                    var rowIndex = baseRowTemplateIndex_Table4 + i + 1;

                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title            = "检查时间",
                        RowIndex         = rowIndex,
                        ColumnIndex      = 1,
                        Value            = item.HealthDate.HasValue ? item.HealthDate.Value.ToString("yyyy年MM月") : "",
                        TemplateRowIndex = baseRowTemplateIndex_Table4
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检项目-粉尘",
                        RowIndex    = rowIndex,
                        ColumnIndex = 2,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检项目-毒物",
                        RowIndex    = rowIndex,
                        ColumnIndex = 3,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检项目-物理因素",
                        RowIndex    = rowIndex,
                        ColumnIndex = 4,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "健康监护类型-上岗前",
                        RowIndex    = rowIndex,
                        ColumnIndex = 5,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "健康监护类型-在岗期间",
                        RowIndex    = rowIndex,
                        ColumnIndex = 6,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "健康监护类型-离岗时",
                        RowIndex    = rowIndex,
                        ColumnIndex = 7,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检结果-正常",
                        RowIndex    = rowIndex,
                        ColumnIndex = 8,
                        Value       = item.Result
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检结果-复查",
                        RowIndex    = rowIndex,
                        ColumnIndex = 9,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检结果-确诊",
                        RowIndex    = rowIndex,
                        ColumnIndex = 10,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检结果-禁忌",
                        RowIndex    = rowIndex,
                        ColumnIndex = 11,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检结果-疑似",
                        RowIndex    = rowIndex,
                        ColumnIndex = 12,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检项目-其他病患",
                        RowIndex    = rowIndex,
                        ColumnIndex = 13,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "复查时间",
                        RowIndex    = rowIndex,
                        ColumnIndex = 14,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "复查情况",
                        RowIndex    = rowIndex,
                        ColumnIndex = 15,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "复查结论",
                        RowIndex    = rowIndex,
                        ColumnIndex = 16,
                        Value       = ""
                    });
                    excelSheet.Cells.Add(new ExcelSheetCellModel()
                    {
                        Title       = "体检单位",
                        RowIndex    = rowIndex,
                        ColumnIndex = 17,
                        Value       = item.HealthByCompany
                    });
                }

                totalMoveRowCount += healthResultList.Count;
            }

            #endregion

            #region 职业病诊疗情况

            baseRowTemplateIndex_Table5 += totalMoveRowCount;

            #endregion

            excelModel.Sheets.Add(excelSheet);

            _importExportService.ExportWithTemplateExtend(filePath, excelModel);
        }