package com.rongwei.sfcommon.sys.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rongwe.scentity.domian.AspSafetyPerformanceAppraisal;
import com.rongwe.scentity.domian.AspSafetyPerformanceAppraisalDetail;
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
import com.rongwei.rwcommon.base.R;
import com.rongwei.rwcommon.utils.SecurityUtil;
import com.rongwei.safecommon.utils.JSCommonUtils;
import com.rongwei.sfcommon.sys.dao.AspSafetyPerformanceAppraisalDao;
import com.rongwei.sfcommon.sys.service.AspSafetyPerformanceAppraisalDetailService;
import com.rongwei.sfcommon.sys.service.AspSafetyPerformanceAppraisalService;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


@Service
@Transactional
public class AspSafetyPerformanceAppraisalServiceImpl extends ServiceImpl<AspSafetyPerformanceAppraisalDao, AspSafetyPerformanceAppraisal> implements AspSafetyPerformanceAppraisalService {
    @Autowired
    private AspSafetyPerformanceAppraisalDetailService aspSafetyPerformanceAppraisalDetailService;


    @Override
    public R importFile(MultipartFile file, String type) {
        try {
            Sheet sheet = new XSSFWorkbook(file.getInputStream()).getSheetAt(0);
            int lastRowNum = sheet.getLastRowNum();
            String fileName = file.getOriginalFilename().replace(".xlsx", "").replace(".xls", "");
            //判断多行表头是否有问题
            //跳过第0行，开始分析第1行
            Row row1 = sheet.getRow(1);
            String name1 = row1.getCell(0) == null ? "" : row1.getCell(0).toString().trim();
            if (!name1.equals("车间名称")) {
                return R.error("第2行，第1列，表头模板有误！");
            }
            String name2 = row1.getCell(1) == null ? "" : row1.getCell(1).toString().trim();
            if (!name2.equals("车间人数")) {
                return R.error("第2行，第2列，表头模板有误！");
            }
            String name3 = row1.getCell(2) == null ? "" : row1.getCell(2).toString().trim();
            if (!name3.equals("集团公司安全监管（20分）")) {
                return R.error("第2行，第3列，表头模板有误！");
            }
            String name4 = row1.getCell(10) == null ? "" : row1.getCell(10).toString().trim();
            if (!name4.equals("公司内部安全监管（10分）")) {
                return R.error("第2行，第11列，表头模板有误！");
            }
            String name5 = row1.getCell(19) == null ? "" : row1.getCell(19).toString().trim();
            if (!name5.equals("车间自我安全管理（10分）")) {
                return R.error("第2行，第20列，表头模板有误！");
            }
            String name6 = row1.getCell(22) == null ? "" : row1.getCell(22).toString().trim();
            if (!name6.equals("工伤管理（50分）")) {
                return R.error("第2行，第23列，表头模板有误！");
            }
            String name7 = row1.getCell(27) == null ? "" : row1.getCell(27).toString().trim();
            if (!name7.equals("车间、部门安全工作配合情况")) {
                return R.error("第2行，第28列，表头模板有误！");
            }
            String name8 = row1.getCell(31) == null ? "" : row1.getCell(31).toString().trim();
            if (!name8.equals("扣分合计")) {
                return R.error("第2行，第32列，表头模板有误！");
            }
            String name9 = row1.getCell(32) == null ? "" : row1.getCell(32).toString().trim();
            if (!name9.equals("车间名称")) {
                return R.error("第2行，第33列，表头模板有误！");
            }
            String name10 = row1.getCell(33) == null ? "" : row1.getCell(33).toString().trim();
            if (!name10.equals("车间人数")) {
                return R.error("第2行，第34列，表头模板有误！");
            }
            String name11 = row1.getCell(34) == null ? "" : row1.getCell(34).toString().trim();
            if (!name11.equals("加分项")) {
                return R.error("第2行，第35列，表头模板有误！");
            }
            String name12 = row1.getCell(42) == null ? "" : row1.getCell(42).toString().trim();
            if (!name12.equals("加分合计")) {
                return R.error("第2行，第41列，表头模板有误！");
            }
            String name13 = row1.getCell(43) == null ? "" : row1.getCell(43).toString().trim();
            if (!name13.equals("综合得分情况")) {
                return R.error("第2行，第44列，表头模板有误！");
            }
            //分析第2行
            Row row2 = sheet.getRow(2);
            String name14 = row2.getCell(2) == null ? "" : row2.getCell(2).toString().trim();
            if (!name14.equals("第三方或执法检查")) {
                return R.error("第3行，第3列，表头模板有误！");
            }
            String name15 = row2.getCell(3) == null ? "" : row2.getCell(3).toString().trim();
            if (!name15.equals("集团月度检查隐患条数")) {
                return R.error("第3行，第4列，表头模板有误！");
            }
            String name16 = row2.getCell(4) == null ? "" : row2.getCell(4).toString().trim();
            if (!name16.equals("集团季度综合检查隐患条数")) {
                return R.error("第3行，第5列，表头模板有误！");
            }
            String name17 = row2.getCell(5) == null ? "" : row2.getCell(5).toString().trim();
            if (!name17.equals("监控/集团安环部现场检查隐患条数")) {
                return R.error("第3行，第6列，表头模板有误！");
            }
            String name17_1 = row2.getCell(6) == null ? "" : row2.getCell(6).toString().trim();
            if (!name17_1.equals("集团燃气专项检查隐患条数")) {
                return R.error("第3行，第7列，表头模板有误！");
            }
            String name17_2 = row2.getCell(7) == null ? "" : row2.getCell(7).toString().trim();
            if (!name17_2.equals("集团日常巡查隐患条数")) {
                return R.error("第3行，第8列，表头模板有误！");
            }
            String name18 = row2.getCell(8) == null ? "" : row2.getCell(8).toString().trim();
            if (!name18.equals("考试或提问不合格人数")) {
                return R.error("第3行，第9列，表头模板有误！");
            }
            String name19 = row2.getCell(9) == null ? "" : row2.getCell(9).toString().trim();
            if (!name19.equals("集团考核通报（50元/扣0.5分）")) {
                return R.error("第3行，第10列，表头模板有误！");
            }
            String name20 = row2.getCell(10) == null ? "" : row2.getCell(10).toString().trim();
            if (!name20.equals("月度安全检查")) {
                return R.error("第3行，第11列，表头模板有误！");
            }
            String name20_1 = row2.getCell(11) == null ? "" : row2.getCell(11).toString().trim();
            if (!name20_1.equals("危险化学品检查")) {
                return R.error("第3行，第12列，表头模板有误！");
            }
            String name20_2 = row2.getCell(12) == null ? "" : row2.getCell(12).toString().trim();
            if (!name20_2.equals("高低压二氧化碳灭火系统检查")) {
                return R.error("第3行，第13列，表头模板有误！");
            }
            String name20_3 = row2.getCell(13) == null ? "" : row2.getCell(13).toString().trim();
            if (!name20_3.equals("危废仓库安全检查")) {
                return R.error("第3行，第14列，表头模板有误！");
            }
            String name21 = row2.getCell(14) == null ? "" : row2.getCell(14).toString().trim();
            if (!name21.equals("安全部日常巡查条数")) {
                return R.error("第3行，第15列，表头模板有误！");
            }
            String name22 = row2.getCell(15) == null ? "" : row2.getCell(15).toString().trim();
            if (!name22.equals("复查整改率")) {
                return R.error("第3行，第16列，表头模板有误！");
            }
            String name23 = row2.getCell(16) == null ? "" : row2.getCell(16).toString().trim();
            if (!name23.equals("车间员工违章率（违章次数/车间总人数）")) {
                return R.error("第3行，第17列，表头模板有误！");
            }
            String name24 = row2.getCell(18) == null ? "" : row2.getCell(18).toString().trim();
            if (!name24.equals("公司考核通报（50元/扣0.5分）")) {
                return R.error("第3行，第19列，表头模板有误！");
            }
            String name25 = row2.getCell(19) == null ? "" : row2.getCell(19).toString().trim();
            if (!name25.equals("公司对车间提问合格率")) {
                return R.error("第3行，第20列，表头模板有误！");
            }
            String name26 = row2.getCell(20) == null ? "" : row2.getCell(20).toString().trim();
            if (!name26.equals("车间自查违章率")) {
                return R.error("第3行，第21列，表头模板有误！");
            }
            String name27 = row2.getCell(21) == null ? "" : row2.getCell(21).toString().trim();
            if (!name27.equals("车间级隐患排查条数")) {
                return R.error("第3行，第22列，表头模板有误！");
            }
            String name28 = row2.getCell(22) == null ? "" : row2.getCell(22).toString().trim();
            if (!name28.equals("安全事件或未遂事件起数")) {
                return R.error("第3行，第23列，表头模板有误！");
            }
            String name29 = row2.getCell(23) == null ? "" : row2.getCell(23).toString().trim();
            if (!name29.equals("费用（元）")) {
                return R.error("第3行，第24列，表头模板有误！");
            }
            String name30 = row2.getCell(24) == null ? "" : row2.getCell(24).toString().trim();
            if (!name30.equals("工伤事故起数")) {
                return R.error("第3行，第25列，表头模板有误！");
            }
            String name31 = row2.getCell(25) == null ? "" : row2.getCell(25).toString().trim();
            if (!name31.equals("费用（元）")) {
                return R.error("第3行，第26列，表头模板有误！");
            }
            String name32 = row2.getCell(26) == null ? "" : row2.getCell(26).toString().trim();
            if (!name32.equals("千人工伤率（‰）")) {
                return R.error("第3行，第27列，表头模板有误！");
            }
            String name33 = row2.getCell(27) == null ? "" : row2.getCell(27).toString().trim();
            if (!name33.equals("专项开展不到位、不及时、效果不佳情况")) {
                return R.error("第3行，第28列，表头模板有误！");
            }
            String name34 = row2.getCell(29) == null ? "" : row2.getCell(29).toString().trim();
            if (!name34.equals("车间、部门上交的资料质量差、标准低情况")) {
                return R.error("第3行，第30列，表头模板有误！");
            }
            String name35 = row2.getCell(34) == null ? "" : row2.getCell(34).toString().trim();
            if (!name35.equals("车间自行组织预防安全培训、活动等/次数")) {
                return R.error("第3行，第35列，表头模板有误！");
            }
            String name36 = row2.getCell(36) == null ? "" : row2.getCell(36).toString().trim();
            if (!name36.equals("迎接外部检查无隐患问题/次数")) {
                return R.error("第3行，第37列，表头模板有误！");
            }
            String name37 = row2.getCell(38) == null ? "" : row2.getCell(38).toString().trim();
            if (!name37.equals("车间、部门承接公司安全活动次数")) {
                return R.error("第3行，第39列，表头模板有误！");
            }
            String name37_1 = row2.getCell(40) == null ? "" : row2.getCell(40).toString().trim();
            if (!name37_1.equals("集团公司、公司奖励（50元/加0.5分）")) {
                return R.error("第3行，第41列，表头模板有误！");
            }
            //分析第3行
            Row row3 = sheet.getRow(3);
            String name38 = row3.getCell(16) == null ? "" : row3.getCell(16).toString().trim();
            if (!name38.equals("违章考核起数")) {
                return R.error("第4行，第17列，表头模板有误！");
            }
            String name39 = row3.getCell(17) == null ? "" : row3.getCell(17).toString().trim();
            if (!name39.equals("人员违章率")) {
                return R.error("第4行，第18列，表头模板有误！");
            }
            //================表头分析结束================


            //主表保存
            AspSafetyPerformanceAppraisal main = new AspSafetyPerformanceAppraisal();
            String id = SecurityUtil.getUUID();
            SysUserVo currentUser = JSCommonUtils.getCurrentUser();
            DateTime date = DateUtil.date();
            main.setId(id);
            main.setName(fileName);
            main.setType(type);
            main.setCreateusername(currentUser.getName());
            main.setCreateuserid(currentUser.getId());
            main.setModifyusername(currentUser.getName());
            main.setModifyuserid(currentUser.getId());
            main.setCreatedate(date);
            main.setModifydate(date);
            //获取当前用户的tenantId
//            main.setTenantid(currentUser.getTenantid());
            main.setTenantid(currentUser.getOrganizationDoList().get(0).getFullpid().split(",")[1]);
            this.save(main);

            List<AspSafetyPerformanceAppraisalDetail> res = new ArrayList<>();
            for (int i = 4; i <= lastRowNum; i++) {
                AspSafetyPerformanceAppraisalDetail detail = new AspSafetyPerformanceAppraisalDetail();
                Row row = sheet.getRow(i);
                if (ObjectUtil.isEmpty(row)) {
                    continue;
                }
                //遍历所有数据，组装进入detail，最终进入res
                //判断行数为奇数还是偶数
                if (i % 2 == 0) {
                    String departname = row.getCell(0) == null ? "" : row.getCell(0).toString().trim();
                    String departpeople = row.getCell(1) == null ? "" : row.getCell(1).toString().trim();
                    String otherinspection = row.getCell(2) == null ? "" : row.getCell(2).toString().trim();
                    String monthlyinspection = row.getCell(3) == null ? "" : row.getCell(3).toString().trim();
                    String quarterlyinspection = row.getCell(4) == null ? "" : row.getCell(4).toString().trim();
                    String onstieinspection = row.getCell(5) == null ? "" : row.getCell(5).toString().trim();
                    String numberofcheckdanger = row.getCell(6) == null ? "" : row.getCell(6).toString().trim();
                    String numberofdaycheckdanger = row.getCell(7) == null ? "" : row.getCell(7).toString().trim();
                    String faildpeople = row.getCell(8) == null ? "" : row.getCell(8).toString().trim();
                    String assessmentreport = row.getCell(9) == null ? "" : row.getCell(9).toString().trim();
                    String monthlysafetyinspection = row.getCell(10) == null ? "" : row.getCell(10).toString().trim();
                    String dangerouschemicalcheck = row.getCell(11) == null ? "" : row.getCell(11).toString().trim();
                    String lowpressurecheck = row.getCell(12) == null ? "" : row.getCell(12).toString().trim();
                    String hazardouswarehouse = row.getCell(13) == null ? "" : row.getCell(13).toString().trim();
                    String dailyinspection = row.getCell(14) == null ? "" : row.getCell(14).toString().trim();
                    String reviewrate = row.getCell(15) == null ? "" : row.getCell(15).toString().trim();
                    String violationassessment = row.getCell(16) == null ? "" : row.getCell(16).toString().trim();
                    String personnelviolationrate = row.getCell(17) == null ? "" : row.getCell(17).toString().trim();
                    String commpanyassessmentreport = row.getCell(18) == null ? "" : row.getCell(18).toString().trim();
                    String rateforworkshopquestion = row.getCell(19) == null ? "" : row.getCell(19).toString().trim();
                    String workshopselfrate = row.getCell(20) == null ? "" : row.getCell(20).toString().trim();
                    String numberofworkshoplevel = row.getCell(21) == null ? "" : row.getCell(21).toString().trim();
                    String numberofsafetyincident = row.getCell(22) == null ? "" : row.getCell(22).toString().trim();
                    String cost1 = row.getCell(23) == null ? "" : row.getCell(23).toString().trim();
                    String numberofaccident = row.getCell(24) == null ? "" : row.getCell(24).toString().trim();
                    String cost2 = row.getCell(25) == null ? "" : row.getCell(25).toString().trim();
                    String thousandartificialinjuryrate = row.getCell(26) == null ? "" : row.getCell(26).toString().trim();
                    String numberofspecialproject = row.getCell(27) == null ? "" : row.getCell(27).toString().trim();
                    String numberofbadmatterials = row.getCell(29) == null ? "" : row.getCell(29).toString().trim();
                    String totaldeductionpoints = row.getCell(31) == null ? "" : row.getCell(31).toString().trim();
                    String trainingbyself = row.getCell(34) == null ? "" : row.getCell(34).toString().trim();
                    String trainingbyout = row.getCell(36) == null ? "" : row.getCell(36).toString().trim();
                    String trainingbycompany = row.getCell(38) == null ? "" : row.getCell(38).toString().trim();
                    String companyrewards = row.getCell(40) == null ? "" : row.getCell(40).toString().trim();

                    String totalbonuspoints = row.getCell(42) == null ? "" : row.getCell(42).toString().trim();
                    String totalscore = row.getCell(43) == null ? "" : row.getCell(43).toString().trim();

                    if (ObjectUtil.isEmpty(departname)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(departpeople)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(otherinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(monthlyinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(quarterlyinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(onstieinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofcheckdanger)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofdaycheckdanger)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(faildpeople)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(assessmentreport)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(monthlysafetyinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(dangerouschemicalcheck)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(lowpressurecheck)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(hazardouswarehouse)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(dailyinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(reviewrate)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(violationassessment)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(personnelviolationrate)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(commpanyassessmentreport)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(rateforworkshopquestion)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(workshopselfrate)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofworkshoplevel)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofsafetyincident)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(cost1)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofaccident)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(cost2)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(thousandartificialinjuryrate)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofspecialproject)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofbadmatterials)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(totaldeductionpoints)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(trainingbyself)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(trainingbyout)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(trainingbycompany)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(companyrewards)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(totalbonuspoints)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(totalscore)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }

                    detail.setDepartname(departname);
                    detail.setDepartpeople(departpeople);
                    detail.setOtherinspection(otherinspection);
                    detail.setMonthlyinspection(monthlyinspection);
                    detail.setQuarterlyinspection(quarterlyinspection);
                    detail.setOnstieinspection(onstieinspection);
                    detail.setNumberofcheckdanger(numberofcheckdanger);
                    detail.setNumberofdaycheckdanger(numberofdaycheckdanger);
                    detail.setFaildpeople(faildpeople);
                    detail.setAssessmentreport(assessmentreport);
                    detail.setMonthlysafetyinspection(monthlysafetyinspection);
                    detail.setDangerouschemicalcheck(dangerouschemicalcheck);
                    detail.setLowpressurecheck(lowpressurecheck);
                    detail.setHazardouswarehouse(hazardouswarehouse);
                    detail.setDailyinspection(dailyinspection);
                    detail.setReviewrate(reviewrate);
                    detail.setViolationassessment(violationassessment);
                    detail.setPersonnelviolationrate(personnelviolationrate);
//                    detail.setViolationscore(violationscore);
                    detail.setCommpanyassessmentreport(commpanyassessmentreport);
                    detail.setRateforworkshopquestion(rateforworkshopquestion);
                    detail.setWorkshopselfrate(workshopselfrate);
                    detail.setNumberofworkshoplevel(numberofworkshoplevel);
                    detail.setNumberofsafetyincident(numberofsafetyincident);
                    detail.setCost1(cost1);
//                    detail.setScore1(score1);
                    detail.setNumberofaccident(numberofaccident);
                    detail.setCost2(cost2);
//                    detail.setScore2(score2);
                    detail.setThousandartificialinjuryrate(thousandartificialinjuryrate);
                    detail.setNumberofspecialproject(numberofspecialproject);
                    detail.setNumberofbadmatterials(numberofbadmatterials);
                    detail.setTotaldeductionpoints(totaldeductionpoints);
                    detail.setTrainingbyself(trainingbyself);
                    detail.setTrainingbyout(trainingbyout);
                    detail.setTrainingbycompany(trainingbycompany);
                    detail.setCompanyrewards(companyrewards);
                    detail.setTotalbonuspoints(totalbonuspoints);
                    detail.setTotalscore(totalscore);
                    detail.setType(((i / 2) - 1) + ".1");
                    detail.setMainid(id);
                    detail.setId(SecurityUtil.getUUID());

                    detail.setCreateusername(currentUser.getName());
                    detail.setCreateuserid(currentUser.getId());
                    detail.setModifyusername(currentUser.getName());
                    detail.setModifyuserid(currentUser.getId());
                    detail.setCreatedate(date);
                    detail.setModifydate(date);
                    //获取当前用户的tenantId
//                  detail.setTenantid(currentUser.getTenantid());
                    detail.setTenantid(currentUser.getOrganizationDoList().get(0).getFullpid().split(",")[1]);

                    res.add(detail);
                } else {
                    String otherinspection = row.getCell(2) == null ? "" : row.getCell(2).toString().trim();
                    String monthlyinspection = row.getCell(3) == null ? "" : row.getCell(3).toString().trim();
                    String quarterlyinspection = row.getCell(4) == null ? "" : row.getCell(4).toString().trim();
                    String onstieinspection = row.getCell(5) == null ? "" : row.getCell(5).toString().trim();
                    String numberofcheckdanger = row.getCell(6) == null ? "" : row.getCell(6).toString().trim();
                    String numberofdaycheckdanger = row.getCell(7) == null ? "" : row.getCell(7).toString().trim();
                    String faildpeople = row.getCell(8) == null ? "" : row.getCell(8).toString().trim();
                    String assessmentreport = row.getCell(9) == null ? "" : row.getCell(9).toString().trim();
                    String monthlysafetyinspection = row.getCell(10) == null ? "" : row.getCell(10).toString().trim();
                    String dangerouschemicalcheck = row.getCell(11) == null ? "" : row.getCell(11).toString().trim();
                    String lowpressurecheck = row.getCell(12) == null ? "" : row.getCell(12).toString().trim();
                    String hazardouswarehouse = row.getCell(13) == null ? "" : row.getCell(13).toString().trim();
                    String dailyinspection = row.getCell(14) == null ? "" : row.getCell(14).toString().trim();
                    String reviewrate = row.getCell(15) == null ? "" : row.getCell(15).toString().trim();
                    String violationscore = row.getCell(16) == null ? "" : row.getCell(16).toString().trim();
                    String commpanyassessmentreport = row.getCell(18) == null ? "" : row.getCell(18).toString().trim();
                    String rateforworkshopquestion = row.getCell(19) == null ? "" : row.getCell(19).toString().trim();
                    String workshopselfrate = row.getCell(20) == null ? "" : row.getCell(20).toString().trim();
                    String numberofworkshoplevel = row.getCell(21) == null ? "" : row.getCell(21).toString().trim();
                    String score1 = row.getCell(22) == null ? "" : row.getCell(22).toString().trim();
                    String score2 = row.getCell(24) == null ? "" : row.getCell(24).toString().trim();
                    String thousandartificialinjuryrate = row.getCell(26) == null ? "" : row.getCell(26).toString().trim();
                    String numberofspecialproject = row.getCell(27) == null ? "" : row.getCell(27).toString().trim();
                    String numberofbadmatterials = row.getCell(29) == null ? "" : row.getCell(29).toString().trim();
//                    String totaldeductionpoints = row.getCell(26) == null ? "" : row.getCell(26).toString().trim();
                    String trainingbyself = row.getCell(34) == null ? "" : row.getCell(34).toString().trim();
                    String trainingbyout = row.getCell(36) == null ? "" : row.getCell(36).toString().trim();
                    String trainingbycompany = row.getCell(38) == null ? "" : row.getCell(38).toString().trim();
                    String companyrewards = row.getCell(40) == null ? "" : row.getCell(40).toString().trim();
//                    String totalbonuspoints = row.getCell(35) == null ? "" : row.getCell(35).toString().trim();
//                    String totalscore = row.getCell(36) == null ? "" : row.getCell(36).toString().trim();

                    if (ObjectUtil.isEmpty(otherinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(monthlyinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(quarterlyinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(onstieinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(faildpeople)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(assessmentreport)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(monthlysafetyinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(dailyinspection)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(reviewrate)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(violationscore)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(commpanyassessmentreport)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(rateforworkshopquestion)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(workshopselfrate)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofworkshoplevel)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(score1)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(score2)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(thousandartificialinjuryrate)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofspecialproject)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(numberofbadmatterials)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(trainingbyself)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(trainingbyout)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(trainingbycompany)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }
                    if (ObjectUtil.isEmpty(companyrewards)) {
                        return R.error("第" + (i + 1) + "行数据存在空值，请检查表格！");
                    }


//                    detail.setDepartname(departname);
//                    detail.setDepartpeople(departpeople);
                    detail.setOtherinspection(otherinspection);
                    detail.setMonthlyinspection(monthlyinspection);
                    detail.setQuarterlyinspection(quarterlyinspection);
                    detail.setOnstieinspection(onstieinspection);
                    detail.setNumberofcheckdanger(numberofcheckdanger);
                    detail.setNumberofdaycheckdanger(numberofdaycheckdanger);
                    detail.setFaildpeople(faildpeople);
                    detail.setAssessmentreport(assessmentreport);
                    detail.setMonthlysafetyinspection(monthlysafetyinspection);
                    detail.setDangerouschemicalcheck(dangerouschemicalcheck);
                    detail.setLowpressurecheck(lowpressurecheck);
                    detail.setHazardouswarehouse(hazardouswarehouse);
                    detail.setDailyinspection(dailyinspection);
                    detail.setReviewrate(reviewrate);
//                    detail.setViolationassessment(violationassessment);
//                    detail.setPersonnelviolationrate(personnelviolationrate);
                    detail.setViolationscore(violationscore);
                    detail.setCommpanyassessmentreport(commpanyassessmentreport);
                    detail.setRateforworkshopquestion(rateforworkshopquestion);
                    detail.setWorkshopselfrate(workshopselfrate);
                    detail.setNumberofworkshoplevel(numberofworkshoplevel);
//                    detail.setNumberofsafetyincident(numberofsafetyincident);
//                    detail.setCost1(cost1);
                    detail.setScore1(score1);
//                    detail.setNumberofaccident(numberofaccident);
//                    detail.setCost2(cost2);
                    detail.setScore2(score2);
                    detail.setThousandartificialinjuryrate(thousandartificialinjuryrate);
                    detail.setNumberofspecialproject(numberofspecialproject);
                    detail.setNumberofbadmatterials(numberofbadmatterials);
                    detail.setTrainingbyself(trainingbyself);
                    detail.setTrainingbyout(trainingbyout);
                    detail.setTrainingbycompany(trainingbycompany);
                    detail.setCompanyrewards(companyrewards);
                    detail.setType(((i / 2) - 1) + ".2");
                    detail.setMainid(id);
                    detail.setId(SecurityUtil.getUUID());

                    detail.setCreateusername(currentUser.getName());
                    detail.setCreateuserid(currentUser.getId());
                    detail.setModifyusername(currentUser.getName());
                    detail.setModifyuserid(currentUser.getId());
                    detail.setCreatedate(date);
                    detail.setModifydate(date);
                    //获取当前用户的tenantId
//                  detail.setTenantid(currentUser.getTenantid());
                    detail.setTenantid(currentUser.getOrganizationDoList().get(0).getFullpid().split(",")[1]);

                    res.add(detail);
                }


            }
            if (!res.isEmpty()) {
                aspSafetyPerformanceAppraisalDetailService.saveBatch(res);
            }
        } catch (IOException e) {
            R.error("绩效考核导入异常");
        }
        return R.ok();
    }
}
