package com.winsun.controller;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.winsun.auth.core.annotion.Permission;
import com.winsun.auth.core.base.controller.BaseController;
import com.winsun.auth.core.common.model.ResponseData;
import com.winsun.auth.core.shiro.ShiroUser;
import com.winsun.auth.core.util.IOUtils;
import com.winsun.bean.ManagerKpi;
import com.winsun.bean.ZjlWage;
import com.winsun.mapper.ManagerKpiMapper;
import com.winsun.mapper.ZjlWageMapper;
import com.winsun.utils.ExcelDealUtils;
import com.winsun.utils.ImportExcel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * 总经理薪酬管理
 * @Author: pxl
 * @create 2020/4/29 14:08
 */
@Slf4j
@RestController
@RequestMapping("/zjlWage")
public class zjlSalaryController extends BaseController {
    /**
     * 导入
     */
    private static final int HEADER_NUM = -1;
    private static final int SHEET_INDEX = 0;
    /**
     * 总经理薪酬信息模板列名
     */
    private static String SL_month = "月份";
    private static String SL_department = "归属";
    private static String SL_name = "姓名";
    private static String SL_idCard = "身份证";
    private static String SL_company = "分公司";
    private static String SL_attribute = "属性";
    private static String SL_positionWage = "岗位工资";
    private static String SL_performanceBonus = "绩效奖金\n（绩效工资+提成）";
    private static String SL_specialBonus = "专项奖";
    private static String SL_yearEndBonus = "年终奖";
    private static String SL_festivalFee = "节日费(元旦,春节,五一,十一)";
    private static String SL_highSubsidy = "高温补贴(6-10月)";
    private static String SL_correspondenceSubsidy = "通讯补贴";
    private static String SL_tableMoneySubsidy = "餐费补贴";
    private static String SL_trafficSubsidy = "交通补贴";
    private static String SL_specialBonusAutumn = "专项奖（秋营奖励）";
    private static String SL_otherSubsidy = "其他补扣补退";
    private static String SL_endowmentInsurancePersonal = "个人养老保险";
    private static String SL_unenploymentInsurancePersonal = "个人缴纳失业保险";
    private static String SL_medicarePersonal = "个人缴纳医疗保险";
    private static String SL_reservedFund = "个人缴纳住房公积金";
    private static String SL_reservedFundTax = "个税";
    private static String SL_yearEndBonusTax = "年终奖个税";
    private static String SL_otherFeePersonal = "个人其他补交补退";
    private static String SL_duesPersonal = "个人工会费";
    private static String SL_endowmentInsuranceUnit = "单位养老保险";
    private static String SL_unenploymentInsuranceUnit = "单位失业保险";
    private static String SL_medicareUnit = "单位医疗保险";
    private static String SL_employmentInjuryInsuranceUnit = "单位工伤保险";
    private static String SL_birthInsuranceUnit = "单位生育保险";
    private static String SL_illnessInsuranceUnit = "重大疾病保险";
    private static String SL_reservedFundUnit = "单位公积金";
    private static String SL_laborUnionFeeUnit = "工会计提";
    private static String SL_accidentInsuranceUnit= "商业意外险";
    private static String SL_disabilityInsuranceUnit = "残保金";
    private static String SL_otherFeeUnit = "单位其他补交补退";
    private static String SL_additionMsg = "附加信息";
    private static String SL_manageFee = "邮电人才服务管理费（200/人）";
    private static String SL_endowmentInsurancePersonal2 = "个人缴纳养老保险2";
    private static String SL_unenploymentInsurancePersonal2 = "个人缴纳失业保险2";
    private static String SL_medicarePersonal2 = "个人缴纳医疗保险2";
    private static String SL_resveredFundPersonal2 = "个人缴纳住房公积金2";
    private static String SL_endowmentInsuranceUnit2 = "单位养老保险2";
    private static String SL_unenploymentInsuranceUnit2 = "单位失业保险2";
    private static String SL_medicareUnit2 = "单位医疗保险2";
    private static String SL_employmentInjuryInsuranceUnit2 = "单位工伤保险2";
    private static String SL_birthInsuranceUnit2 = "单位生育保险2";
    private static String SL_illnessInsuranceUnit2 = "重大疾病保险企业缴纳2";
    private static String SL_reservedInsuranceUnit2 = "单位住房公积金2";
    private static String SL_wage = "本月计税工资";
    private static String SL_wageTax = "本月抵税扣除";
    private static String SL_wageTaxAfter = "本月工资抵税";
    private static String SL_lastYearEndBonus = "年终奖应税";
    private static String SL_lastYearEndBonusTax = "年终奖个税计算";
    private static String SL_bankAccount = "银行账号";
    private static String SL_isDuDao = "是否督导";

    @Autowired
    private ZjlWageMapper zjlWageMapper;
    @Autowired
    private ManagerKpiMapper managerKpiMapper;
    @Autowired
    @Qualifier("redisStringTemplate")
    private RedisTemplate redisTemplate;


    /**
     * 总经理薪酬删除
     * @param id 需要删除的id
     * @return
     */
    @Permission(menuname = "删除总经理薪酬信息", value = "delete", method = RequestMethod.POST)
    public ResponseData<String> delete(@RequestParam(name="id", required = false) Integer id) {
        ShiroUser user = getShiroUser();
        if (!user.getRoleNames().stream().anyMatch(roleName -> StringUtils.equalsAny(roleName, "超级管理员"))) {
            return ResponseData.error("无数据权限");
        }
        if(StringUtils.isNotBlank(id.toString())){
            zjlWageMapper.deleteById(id);
            return ResponseData.success("操作成功！");
        }
        return ResponseData.error("删除id不能为空!");
    }

    /**
     * 修改总经理薪酬信息
     * @param zjlKpi 编辑对象json字符串
     * @return
     */
    /*@Permission(menuname = "修改总经理薪酬信息", value = "update", method = RequestMethod.POST)
    public ResponseData<String> update(@RequestParam("zjlKpi") String zjlKpi) {
        ShiroUser user = getShiroUser();
        if (!user.getRoleNames().stream().anyMatch(roleName -> StringUtils.equalsAny(roleName, "超级管理员"))) {
            return ResponseData.error("无数据权限");
        }
        LzKpi pro = JSON.parseObject(zjlKpi, LzKpi.class);
        Wrapper wrapper = new EntityWrapper<>();
        wrapper.eq("id", pro.getId());
        Map<String, Object> dataMapping = new HashMap<>();
        dataMapping.put("report_daily", pro.getReportDaily());
        dataMapping.put("collective_sales", pro.getCollectiveSales());
        dataMapping.put("weekly_meeting", pro.getWeeklyMeeting());
        dataMapping.put("organ_training", pro.getOrganTraining());
        dataMapping.put("design_plan", pro.getDesignPlan());
        dataMapping.put("kpi", pro.getKpi());
        dataMapping.put("user_id", pro.getUserId());
        dataMapping.put("month", pro.getMonth());
        dataMapping.put("is_Del", pro.getIsDel());
        ZjlWageMapper.updateForSet(MyBatisPlusUpdateUtils.toUpdateSet(dataMapping), wrapper);
        return ResponseData.success("修改成功！");
    }*/

    /**
     * @param name
     * @param month
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Permission(menuname = "查询总经理薪酬信息", value = "list", method = RequestMethod.POST)
    public ResponseData<Page<ZjlWage>> listProduct(
            @RequestParam(name = "name", required = false) String name,@RequestParam(name = "month", required = false) String month,
            @RequestParam(name = "pageNo") int pageNo, @RequestParam(name = "pageSize") int pageSize) {
        ShiroUser user = getShiroUser();

        Page<ZjlWage> page = new Page<>(pageNo, pageSize);
        List<ZjlWage> dataList = new LinkedList<>();
        Wrapper<ZjlWage> wrapper = new EntityWrapper();
        wrapper.like(StringUtils.isNotBlank(name), "name", name, SqlLike.DEFAULT);
        if(StringUtils.isNotBlank(month)){
            String[] months = month.split("\\,");
            if(!month.equals(",") && StringUtils.isNotEmpty(month)){
                String m1 = months[0].substring(0,7);
                String month1 = m1.substring(0,4) + m1.substring(5);
                String m2 = months[1].substring(0,7);
                String month2 = m2.substring(0,4) + m2.substring(5);
                wrapper.ge(StringUtils.isNotBlank(month1),"month",month1);
                wrapper.le(StringUtils.isNotBlank(month2),"month",month2);
            }
        }
        List<ZjlWage> aPackage = zjlWageMapper.selectPage(page, wrapper);
        page.setRecords(aPackage);
        return ResponseData.success(page, "查询成功！");
    }

    /**
     * @param month
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Permission(menuname = "导出总经理薪酬信息", value = "excelOut", method = RequestMethod.POST)
    public void excelOut(
            @RequestParam(name = "name", required = false) String name,@RequestParam(name = "month", required = false) String month,
            @RequestParam(name = "pageNo") int pageNo, @RequestParam(name = "pageSize") int pageSize
    )  throws IOException {
        ShiroUser user = getShiroUser();
        List<Map<String,Object>> list = new LinkedList<>();
        Wrapper<ZjlWage> wrapper = new EntityWrapper();
        wrapper.like(StringUtils.isNotBlank(name), "name", name, SqlLike.DEFAULT);
        if(StringUtils.isNotBlank(month)){
            String[] months = month.split("\\,");
            if(!month.equals(",") && StringUtils.isNotEmpty(month)){
                String m1 = months[0].substring(0,7);
                String month1 = m1.substring(0,4) + m1.substring(5);
                String m2 = months[1].substring(0,7);
                String month2 = m2.substring(0,4) + m2.substring(5);
                wrapper.ge(StringUtils.isNotBlank(month1),"month",month1);
                wrapper.le(StringUtils.isNotBlank(month2),"month",month2);
            }
        }
        List<ZjlWage> zjlWages = zjlWageMapper.selectList(wrapper);
        if(zjlWages.size()==0){
            log.error("查询数据为空！");
        }
        for (ZjlWage zjlWage : zjlWages) {
            Map<String,Object> map = new HashMap<>();
            map.put("id",zjlWage.getId());
            map.put("month",zjlWage.getMonth());
            map.put("department",zjlWage.getDepartment());
            map.put("name",zjlWage.getName());
            map.put("idCard",zjlWage.getIdCard());
            map.put("company",zjlWage.getCompany());
            map.put("attribute",zjlWage.getAttribute());
            map.put("positionWage",zjlWage.getPositionWage());
            map.put("performanceBonus",zjlWage.getPerformanceBonus());
            map.put("specialBonus",zjlWage.getSpecialBonus());
            map.put("yearEndBonus",zjlWage.getYearEndBonus());
            map.put("festivalFee",zjlWage.getFestivalFee());
            map.put("highSubsidy",zjlWage.getHighSubsidy());
            map.put("correspondenceSubsidy",zjlWage.getCorrespondenceSubsidy());
            map.put("tableMoneySubsidy",zjlWage.getTableMoneySubsidy());
            map.put("trafficSubsidy",zjlWage.getTrafficSubsidy());
            map.put("specialBonusAutumn",zjlWage.getSpecialBonusAutumn());
            map.put("otherSubsidy",zjlWage.getOtherSubsidy());
            map.put("totalYf",zjlWage.getTotalYf());
            map.put("endowmentInsurancePersonal",zjlWage.getEndowmentInsurancePersonal());
            map.put("unenploymentInsurancePersonal",zjlWage.getUnenploymentInsurancePersonal());
            map.put("medicarePersonal",zjlWage.getMedicarePersonal());
            map.put("totalInsurance",zjlWage.getTotalInsurance());
            map.put("reservedFund",zjlWage.getReservedFund());
            map.put("reservedFundTax",zjlWage.getReservedFundTax());
            map.put("yearEndBonusTax",zjlWage.getYearEndBonusTax());
            map.put("otherFeePersonal",zjlWage.getOtherFeePersonal());
            map.put("duesPersonal",zjlWage.getDuesPersonal());
            map.put("totalFeePersonal",zjlWage.getTotalFeePersonal());
            map.put("totalSf",zjlWage.getTotalSf());
            map.put("endowmentInsuranceUnit",zjlWage.getEndowmentInsuranceUnit());
            map.put("unenploymentInsuranceUnit", zjlWage.getUnenploymentInsuranceUnit());
            map.put("medicareUnit",zjlWage.getMedicareUnit());
            map.put("employmentInjuryInsuranceUnit",zjlWage.getEmploymentInjuryInsuranceUnit());
            map.put("birthInsuranceUnit",zjlWage.getBirthInsuranceUnit());
            map.put("illnessInsuranceUnit",zjlWage.getIllnessInsuranceUnit());
            map.put("reservedFundUnit",zjlWage.getReservedFundUnit());
            map.put("laborUnionFeeUnit",zjlWage.getLaborUnionFeeUnit());
            map.put("accidentInsuranceUnit",zjlWage.getAccidentInsuranceUnit());
            map.put("disabilityInsuranceUnit",zjlWage.getDisabilityInsuranceUnit());
            map.put("otherFeeUnit",zjlWage.getOtherFeeUnit());
            map.put("totalFeeUnit",zjlWage.getTotalFeeUnit());
            map.put("totalCastPersonal",zjlWage.getTotalCastPersonal());
            map.put("additionMsg",zjlWage.getAdditionMsg());
            map.put("manageFee",zjlWage.getManageFee());
            map.put("totalCastUnit",zjlWage.getTotalCastUnit());
            map.put("endowmentInsurancePersonal2",zjlWage.getEndowmentInsurancePersonal2());
            map.put("unenploymentInsurancePersonal2",zjlWage.getUnenploymentInsurancePersonal2());
            map.put("medicarePersonal2",zjlWage.getMedicarePersonal2());
            map.put("resveredFundPersonal2",zjlWage.getResveredFundPersonal2());
            map.put("endowmentInsuranceUnit2",zjlWage.getEndowmentInsuranceUnit2());
            map.put("unenploymentInsuranceUnit2",zjlWage.getUnenploymentInsuranceUnit2());
            map.put("medicareUnit2",zjlWage.getMedicareUnit2());
            map.put("employmentInjuryInsuranceUnit2",zjlWage.getEmploymentInjuryInsuranceUnit2());
            map.put("birthInsuranceUnit2",zjlWage.getBirthInsuranceUnit2());
            map.put("illnessInsuranceUnit2",zjlWage.getIllnessInsuranceUnit2());
            map.put("reservedInsuranceUnit2",zjlWage.getReservedInsuranceUnit2());
            map.put("totalInsuranceUnit2",zjlWage.getTotalInsuranceUnit2());
            map.put("wage",zjlWage.getWage());
            map.put("wageTax",zjlWage.getWageTax());
            map.put("wageTaxAfter",zjlWage.getWageTaxAfter());
            map.put("lastYearEndBonus",zjlWage.getLastYearEndBonus());
            map.put("lastYearEndBonusTax",zjlWage.getLastYearEndBonusTax());
            map.put("bankAccount",zjlWage.getBankAccount());
            map.put("managerCast",zjlWage.getManagerCast());
            map.put("xzCompanyCast",zjlWage.getXzCompanyCast());
            list.add(map);
        }
        ServletOutputStream os = null;
        XSSFWorkbook workbook = ExcelDealUtils.getWorkBook(ExcelDealUtils.zjlWageExcel("总经理薪酬清单"), list);
        try {
            HttpServletResponse response = getHttpServletResponse();
            response.reset();
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/octet-stream");
            os = response.getOutputStream();
            workbook.write(os);
            os.flush();
        } catch (Exception e) {
            log.error("文件出错！" + e.getMessage(), e);
        } finally {
            IOUtils.closeQuite(workbook, os);
        }
    }

    /**
     * 受理订单模板下载
     *
     * @return
     */
    @Permission(menuname = "总经理总经理薪酬管理信息导入模板", method = RequestMethod.POST, value = "downloadMoBan")
    public ResponseData downloadMoBan() {
        ArrayList<String> columns = new ArrayList<>();
        columns.add(SL_month);
        columns.add(SL_department);
        columns.add(SL_name);
        columns.add(SL_idCard);
        columns.add(SL_company);
        columns.add(SL_attribute);
        columns.add(SL_positionWage);
        columns.add(SL_performanceBonus);
        columns.add(SL_specialBonus);
        columns.add(SL_yearEndBonus);
        columns.add(SL_festivalFee);
        columns.add(SL_highSubsidy);
        columns.add(SL_correspondenceSubsidy);
        columns.add(SL_tableMoneySubsidy);
        columns.add(SL_trafficSubsidy);
        columns.add(SL_specialBonusAutumn);
        columns.add(SL_otherSubsidy);
        columns.add(SL_endowmentInsurancePersonal);
        columns.add(SL_unenploymentInsurancePersonal);
        columns.add(SL_medicarePersonal);
        columns.add(SL_reservedFund);
        columns.add(SL_reservedFundTax);
        columns.add(SL_yearEndBonusTax);
        columns.add(SL_otherFeePersonal);
        columns.add(SL_duesPersonal);
        columns.add(SL_endowmentInsuranceUnit);
        columns.add(SL_unenploymentInsuranceUnit);
        columns.add(SL_medicareUnit);
        columns.add(SL_employmentInjuryInsuranceUnit);
        columns.add(SL_birthInsuranceUnit);
        columns.add(SL_illnessInsuranceUnit);
        columns.add(SL_reservedFundUnit);
        columns.add(SL_laborUnionFeeUnit);
        columns.add(SL_accidentInsuranceUnit);
        columns.add(SL_disabilityInsuranceUnit);
        columns.add(SL_otherFeeUnit);
        columns.add(SL_additionMsg);
        columns.add(SL_manageFee);
        columns.add(SL_endowmentInsurancePersonal2);
        columns.add(SL_unenploymentInsurancePersonal2);
        columns.add(SL_medicarePersonal2);
        columns.add(SL_resveredFundPersonal2);
        columns.add(SL_endowmentInsuranceUnit2);
        columns.add(SL_unenploymentInsuranceUnit2);
        columns.add(SL_medicareUnit2);
        columns.add(SL_employmentInjuryInsuranceUnit2);
        columns.add(SL_birthInsuranceUnit2);
        columns.add(SL_illnessInsuranceUnit2);
        columns.add(SL_reservedInsuranceUnit2);
        columns.add(SL_wage);
        columns.add(SL_wageTax);
        columns.add(SL_wageTaxAfter);
        columns.add(SL_lastYearEndBonus);
        columns.add(SL_lastYearEndBonusTax);
        columns.add(SL_bankAccount);
        columns.add(SL_isDuDao);

        ServletOutputStream os = null;
        XSSFWorkbook workbook = new XSSFWorkbook();
        try {
            //创建工作表
            XSSFSheet sheet = workbook.createSheet("总经理总经理薪酬管理信息");
            sheet.setColumnWidth(0, 3000);
            sheet.setColumnWidth(1, 3000);
            sheet.setColumnWidth(2, 5000);
            sheet.setColumnWidth(3, 3000);
            sheet.setColumnWidth(4, 3000);
            sheet.setColumnWidth(5, 3000);
            sheet.setColumnWidth(6, 3000);
            sheet.setColumnWidth(7, 3000);
            sheet.setColumnWidth(8, 3000);
            sheet.setColumnWidth(9, 3000);
            sheet.setColumnWidth(10, 3000);
            sheet.setColumnWidth(11, 3000);
            sheet.setColumnWidth(12, 5000);
            sheet.setColumnWidth(13, 3000);
            sheet.setColumnWidth(14, 3000);
            sheet.setColumnWidth(15, 3000);
            sheet.setColumnWidth(16, 3000);
            sheet.setColumnWidth(17, 3000);
            sheet.setColumnWidth(18, 3000);
            sheet.setColumnWidth(19, 3000);
            sheet.setColumnWidth(20, 3000);
            sheet.setColumnWidth(21, 3000);
            sheet.setColumnWidth(22, 5000);
            sheet.setColumnWidth(23, 3000);
            sheet.setColumnWidth(24, 3000);
            sheet.setColumnWidth(25, 3000);
            sheet.setColumnWidth(26, 3000);
            sheet.setColumnWidth(27, 3000);
            sheet.setColumnWidth(28, 3000);
            sheet.setColumnWidth(29, 3000);
            sheet.setColumnWidth(30, 3000);
            sheet.setColumnWidth(31, 3000);
            sheet.setColumnWidth(32, 5000);
            sheet.setColumnWidth(33, 3000);
            sheet.setColumnWidth(34, 3000);
            sheet.setColumnWidth(35, 3000);
            sheet.setColumnWidth(36, 3000);
            sheet.setColumnWidth(37, 3000);
            sheet.setColumnWidth(38, 3000);
            sheet.setColumnWidth(39, 3000);
            sheet.setColumnWidth(40, 3000);
            sheet.setColumnWidth(41, 3000);
            sheet.setColumnWidth(42, 5000);
            sheet.setColumnWidth(43, 3000);
            sheet.setColumnWidth(44, 3000);
            sheet.setColumnWidth(45, 3000);
            sheet.setColumnWidth(46, 3000);
            sheet.setColumnWidth(47, 3000);
            sheet.setColumnWidth(48, 3000);
            sheet.setColumnWidth(49, 3000);
            sheet.setColumnWidth(50, 3000);
            sheet.setColumnWidth(51, 3000);
            sheet.setColumnWidth(52, 5000);
            sheet.setColumnWidth(53, 3000);
            sheet.setColumnWidth(54, 3000);
            sheet.setColumnWidth(55, 3000);
            //下拉选项
            /*List<String> fengju = new ArrayList<>();
            fengju.add("受理不成功");
            fengju.add("受理成功");
            sheet = this.getXSSFSheet(sheet, fengju, 1, 1);*/
            //添加表头
            final XSSFRow row = sheet.createRow(0);
            XSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setAlignment(HorizontalAlignment.CENTER);
            columns.forEach(val -> {
                XSSFCell cell = row.createCell(Math.max(row.getLastCellNum(), 0));
                cell.setCellValue(val);
            });
            HttpServletResponse response = getHttpServletResponse();
            response.reset();
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "attachment;fileName=data.xlsx");
            os = response.getOutputStream();
            workbook.write(os);
            os.flush();
        } catch (IOException e) {
            log.error("总经理总经理薪酬管理信息模板文件出错！" + e.getMessage(), e);
        } finally {
            IOUtils.closeQuite(workbook, os);
        }
        return ResponseData.error("总经理总经理薪酬管理信息模板出错");
    }

    XSSFSheet getXSSFSheet(XSSFSheet sheet, List<String> datas, int firstcol, int lastcol) {
        if (datas.size() == 0) {
            return sheet;
        }
        String[] strdata = new String[datas.size()];
        for (int i = 0; i < datas.size(); i++) {
            strdata[i] = datas.get(i);
        }
        XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
        XSSFDataValidationConstraint dvConstraint1 = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(strdata);
        CellRangeAddressList addressList = new CellRangeAddressList(1, 20000, firstcol, lastcol);
        XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint1, addressList);
        sheet.addValidationData(validation);
        return sheet;
    }

    /**
     * 受理订单
     *
     * @param file 上传的数据文件
     * @return
     */
    @Permission(menuname = "上传数据", value = "importDate", method = RequestMethod.POST)
    public ResponseData<String> updateDatas(@RequestParam(name = "file") MultipartFile file) {
        StringBuffer error = new StringBuffer();
        if (!StringUtils.endsWithAny(file.getOriginalFilename(), "xlsx", "xls")) {
            return ResponseData.error("手工上传数据仅支持Excel文件，其他格式不支持！");
        }
        ShiroUser user = getShiroUser();
        // 当前是否有数据权限
        boolean hasDataPermission = user.getRoleNames().stream().anyMatch(data -> StringUtils.equalsAny(data, "活动上单员", "数据管理员", "超级管理员"));
        if (!hasDataPermission) {
            return ResponseData.error("无数据权限！");
        }
        ImportExcel importExcel = null;
        try {
            importExcel = new ImportExcel(file, HEADER_NUM, SHEET_INDEX);
        } catch (Exception e) {
            log.error("总经理总经理薪酬管理信息导入异常", e.getMessage());
            return ResponseData.error("导入异常！");
        }
        List<Map<String, Object>> listMap = importExcel.getDataListMap();
        if (listMap.size() == 1) {
            return ResponseData.error("文件不能为空");
        }
        if (!listMap.get(0).get("a").toString().equals(SL_month)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("b").toString().equals(SL_department)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("c").toString().equals(SL_name)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("d").toString().equals(SL_idCard)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("e").toString().equals(SL_company)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("f").toString().equals(SL_attribute)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("g").toString().equals(SL_positionWage)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("h").toString().equals(SL_performanceBonus)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("i").toString().equals(SL_specialBonus)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("j").toString().equals(SL_yearEndBonus)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("k").toString().equals(SL_festivalFee)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("l").toString().equals(SL_highSubsidy)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("m").toString().equals(SL_correspondenceSubsidy)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("n").toString().equals(SL_tableMoneySubsidy)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("o").toString().equals(SL_trafficSubsidy)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("p").toString().equals(SL_specialBonusAutumn)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("q").toString().equals(SL_otherSubsidy)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("r").toString().equals(SL_endowmentInsurancePersonal)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("s").toString().equals(SL_unenploymentInsurancePersonal)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("t").toString().equals(SL_medicarePersonal)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("u").toString().equals(SL_reservedFund)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("v").toString().equals(SL_reservedFundTax)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("w").toString().equals(SL_yearEndBonusTax)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("x").toString().equals(SL_otherFeePersonal)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("y").toString().equals(SL_duesPersonal)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("z").toString().equals(SL_endowmentInsuranceUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("aa").toString().equals(SL_unenploymentInsuranceUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ab").toString().equals(SL_medicareUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ac").toString().equals(SL_employmentInjuryInsuranceUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ad").toString().equals(SL_birthInsuranceUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ae").toString().equals(SL_illnessInsuranceUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("af").toString().equals(SL_reservedFundUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ag").toString().equals(SL_laborUnionFeeUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ah").toString().equals(SL_accidentInsuranceUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ai").toString().equals(SL_disabilityInsuranceUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("aj").toString().equals(SL_otherFeeUnit)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ak").toString().equals(SL_additionMsg)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("al").toString().equals(SL_manageFee)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("am").toString().equals(SL_endowmentInsurancePersonal2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("an").toString().equals(SL_unenploymentInsurancePersonal2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ao").toString().equals(SL_medicarePersonal2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ap").toString().equals(SL_resveredFundPersonal2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("aq").toString().equals(SL_endowmentInsuranceUnit2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ar").toString().equals(SL_unenploymentInsuranceUnit2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("as").toString().equals(SL_medicareUnit2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("at").toString().equals(SL_employmentInjuryInsuranceUnit2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("au").toString().equals(SL_birthInsuranceUnit2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("av").toString().equals(SL_illnessInsuranceUnit2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("aw").toString().equals(SL_reservedInsuranceUnit2)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ax").toString().equals(SL_wage)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ay").toString().equals(SL_wageTax)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("az").toString().equals(SL_wageTaxAfter)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("ba").toString().equals(SL_lastYearEndBonus)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("bb").toString().equals(SL_lastYearEndBonusTax)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("bc").toString().equals(SL_bankAccount)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        if (!listMap.get(0).get("bd").toString().equals(SL_isDuDao)) {
            return ResponseData.error("模板不对，请选择正确的模板！");
        }
        List<String> accountList = new LinkedList<>();
        List<String> userNameList = new LinkedList<>();
        List<Map<String,Object>> sysUserList = new LinkedList<>();
        //校验数据
        try {
            //校验数据
            for (int i = 1; i < listMap.size(); i++) {
                Map<String, Object> temp = listMap.get(i);
                if (!temp.containsKey("a")) {
                    return ResponseData.error("第" + (i + 1) + "行的月份不能为空");
                }
                if (StringUtils.isBlank(temp.get("a").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的月份不能为空");
                }
                if (!temp.containsKey("b")) {
                    return ResponseData.error("第" + (i + 1) + "行的归属不能为空");
                }
                if (StringUtils.isBlank(temp.get("b").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的归属不能为空");
                }
                if (!temp.containsKey("c")) {
                    return ResponseData.error("第" + (i + 1) + "行的姓名不能为空");
                }
                if (StringUtils.isBlank(temp.get("c").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的姓名不能为空");
                }
                if (!temp.containsKey("d")) {
                    return ResponseData.error("第" + (i + 1) + "行的身份证不能为空");
                }
                if (StringUtils.isBlank(temp.get("d").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的身份证不能为空");
                }
                if (!temp.containsKey("e")) {
                    return ResponseData.error("第" + (i + 1) + "行的分公司不能为空");
                }
                if (StringUtils.isBlank(temp.get("e").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的分公司不能为空");
                }
                if (!temp.containsKey("f")) {
                    return ResponseData.error("第" + (i + 1) + "行的属性不能为空");
                }
                if (StringUtils.isBlank(temp.get("f").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的属性不能为空");
                }
                if (!temp.containsKey("g")) {
                    return ResponseData.error("第" + (i + 1) + "行的岗位工资不能为空");
                }
                if (StringUtils.isBlank(temp.get("g").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的岗位工资不能为空");
                }
                if (!temp.containsKey("h")) {
                    return ResponseData.error("第" + (i + 1) + "行的绩效奖金不能为空");
                }
                if (StringUtils.isBlank(temp.get("h").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的绩效奖金不能为空");
                }
                if (!temp.containsKey("i")) {
                    return ResponseData.error("第" + (i + 1) + "行的专项奖不能为空");
                }
                if (StringUtils.isBlank(temp.get("i").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的专项奖不能为空");
                }
                if (!temp.containsKey("j")) {
                    return ResponseData.error("第" + (i + 1) + "行的年终奖不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("j").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的年终奖不能为空");
                }*/
                if (!temp.containsKey("k")) {
                    return ResponseData.error("第" + (i + 1) + "行的节日费不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("k").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的节日费不能为空");
                }*/
                if (!temp.containsKey("l")) {
                    return ResponseData.error("第" + (i + 1) + "行的高温补贴不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("l").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的高温补贴不能为空");
                }*/
                if (!temp.containsKey("m")) {
                    return ResponseData.error("第" + (i + 1) + "行的通讯补贴不能为空");
                }
                if (StringUtils.isBlank(temp.get("m").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的通讯补贴不能为空");
                }
                if (!temp.containsKey("n")) {
                    return ResponseData.error("第" + (i + 1) + "行的餐费补贴不能为空");
                }
                if (StringUtils.isBlank(temp.get("n").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的餐费补贴不能为空");
                }
                if (!temp.containsKey("o")) {
                    return ResponseData.error("第" + (i + 1) + "行的交通补贴不能为空");
                }
                if (StringUtils.isBlank(temp.get("o").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的交通补贴不能为空");
                }
                if (!temp.containsKey("p")) {
                    return ResponseData.error("第" + (i + 1) + "行的专项奖（秋营奖励）不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("p").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的专项奖（秋营奖励）不能为空");
                }*/
                if (!temp.containsKey("q")) {
                    return ResponseData.error("第" + (i + 1) + "行的其他补扣补退不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("q").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的其他补扣补退不能为空");
                }*/
                if (!temp.containsKey("r")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人养老保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("r").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人养老保险不能为空");
                }*/
                if (!temp.containsKey("s")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳失业保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("s").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳失业保险不能为空");
                }*/
                if (!temp.containsKey("t")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳医疗保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("t").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳医疗保险不能为空");
                }*/
                if (!temp.containsKey("u")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳住房公积金不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("u").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳住房公积金不能为空");
                }*/
                if (!temp.containsKey("v")) {
                    return ResponseData.error("第" + (i + 1) + "行的个税不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("v").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个税不能为空");
                }*/
                if (!temp.containsKey("w")) {
                    return ResponseData.error("第" + (i + 1) + "行的年终奖个税不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("w").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的年终奖个税不能为空");
                }*/
                if (!temp.containsKey("x")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人其他补交补退不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("x").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人其他补交补退不能为空");
                }*/
                if (!temp.containsKey("y")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人工会费不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("y").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人工会费不能为空");
                }*/
                if (!temp.containsKey("z")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位养老保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("z").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位养老保险不能为空");
                }*/
                if (!temp.containsKey("aa")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位失业保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("aa").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位失业保险不能为空");
                }*/
                if (!temp.containsKey("ab")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位医疗保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ab").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位医疗保险不能为空");
                }*/
                if (!temp.containsKey("ac")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位工伤保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ac").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位工伤保险不能为空");
                }*/
                if (!temp.containsKey("ad")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位生育保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ad").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位生育保险不能为空");
                }*/
                if (!temp.containsKey("ae")) {
                    return ResponseData.error("第" + (i + 1) + "行的重大疾病保险不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ae").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的重大疾病保险不能为空");
                }*/
                if (!temp.containsKey("af")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位公积金不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("af").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位公积金不能为空");
                }*/
                if (!temp.containsKey("ag")) {
                    return ResponseData.error("第" + (i + 1) + "行的工会计提不能为空");
                }
                if (StringUtils.isBlank(temp.get("ag").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的工会计提不能为空");
                }
                if (!temp.containsKey("ah")) {
                    return ResponseData.error("第" + (i + 1) + "行的商业意外险不能为空");
                }
                if (StringUtils.isBlank(temp.get("ah").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的商业意外险不能为空");
                }
                if (!temp.containsKey("ai")) {
                    return ResponseData.error("第" + (i + 1) + "行的残保金不能为空");
                }
                if (StringUtils.isBlank(temp.get("ai").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的残保金不能为空");
                }
                if (!temp.containsKey("aj")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位其他补交补退不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("aj").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位其他补交补退不能为空");
                }*/
                if (!temp.containsKey("ak")) {
                    return ResponseData.error("第" + (i + 1) + "行的附加信息不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ak").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的附加信息不能为空");
                }*/
                if (!temp.containsKey("al")) {
                    return ResponseData.error("第" + (i + 1) + "行的邮电人才服务管理费不能为空");
                }
                if (StringUtils.isBlank(temp.get("al").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的高邮电人才服务管理费不能为空");
                }
                if (!temp.containsKey("am")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳养老保险2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("am").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳养老保险2不能为空");
                }*/
                if (!temp.containsKey("an")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳失业保险2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("an").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳失业保险2不能为空");
                }*/
                if (!temp.containsKey("ao")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳医疗保险2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ao").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳医疗保险2不能为空");
                }*/
                if (!temp.containsKey("ap")) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳住房公积金2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ap").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的个人缴纳住房公积金2不能为空");
                }*/
                if (!temp.containsKey("aq")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位养老保险2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("aq").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位养老保险2不能为空");
                }*/
                if (!temp.containsKey("ar")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位失业保险2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ar").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位失业保险2不能为空");
                }*/
                if (!temp.containsKey("as")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位医疗保险2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("as").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位医疗保险2不能为空");
                }*/
                if (!temp.containsKey("at")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位工伤保险2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("at").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位工伤保险2不能为空");
                }*/
                if (!temp.containsKey("au")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位生育保险2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("au").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位生育保险2不能为空");
                }*/
                if (!temp.containsKey("av")) {
                    return ResponseData.error("第" + (i + 1) + "行的重大疾病保险企业缴纳2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("av").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的重大疾病保险企业缴纳2不能为空");
                }*/
                if (!temp.containsKey("aw")) {
                    return ResponseData.error("第" + (i + 1) + "行的单位住房公积金2不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ax").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的单位住房公积金2不能为空");
                }*/
                if (!temp.containsKey("ax")) {
                    return ResponseData.error("第" + (i + 1) + "行的本月计税工资不能为空");
                }
                if (StringUtils.isBlank(temp.get("ax").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的本月计税工资不能为空");
                }
                if (!temp.containsKey("ay")) {
                    return ResponseData.error("第" + (i + 1) + "行的本月抵税扣除不能为空");
                }
                if (StringUtils.isBlank(temp.get("ay").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的本月抵税扣除不能为空");
                }
                if (!temp.containsKey("az")) {
                    return ResponseData.error("第" + (i + 1) + "行的本月工资抵税不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("bz").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的本月工资抵税不能为空");
                }*/
                if (!temp.containsKey("ba")) {
                    return ResponseData.error("第" + (i + 1) + "行的年终奖应税不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("ba").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的年终奖应税不能为空");
                }*/
                if (!temp.containsKey("bb")) {
                    return ResponseData.error("第" + (i + 1) + "行的年终奖个税计算不能为空");
                }
                /*if (StringUtils.isBlank(temp.get("bb").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的年终奖个税计算不能为空");
                }*/
                if (!temp.containsKey("bc")) {
                    return ResponseData.error("第" + (i + 1) + "行的银行账号不能为空");
                }
                if (StringUtils.isBlank(temp.get("bc").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的银行账号不能为空");
                }
                if (!temp.containsKey("bd")) {
                    return ResponseData.error("第" + (i + 1) + "行的是否督导不能为空");
                }
                if (StringUtils.isBlank(temp.get("bd").toString())) {
                    return ResponseData.error("第" + (i + 1) + "行的是否督导不能为空");
                }
            }
        } catch (Exception e) {
            log.error("总经理总经理薪酬管理信息导入异常", e.getMessage());
            return ResponseData.error("导入异常！");
        }

        List<Integer> idList = new ArrayList<>();
        Wrapper<ZjlWage> zjlWageWrapper = new EntityWrapper<>();
        List<ZjlWage> zjlWages = zjlWageMapper.selectList(zjlWageWrapper);
        if(zjlWages.size()>0){
            for (ZjlWage zjlWage : zjlWages) {
                idList.add(zjlWage.getId());
            }
            Wrapper<ZjlWage> zjlWrapper = new EntityWrapper<>();
            zjlWrapper.in("id",idList);
            zjlWageMapper.delete(zjlWrapper);
        }

        int number = 0;
        for (int i = 1; i < listMap.size(); i++) {
            Map<String, Object> map = listMap.get(i);
            ZjlWage zjlWage = new ZjlWage();
            String month = map.get("a").toString();
            zjlWage.setMonth(month);
            zjlWage.setDepartment(map.get("b").toString());
            String name = map.get("c").toString();
            zjlWage.setName(name);
            zjlWage.setIdCard(map.get("d").toString());
            zjlWage.setCompany(map.get("e").toString());
            zjlWage.setAttribute(map.get("f").toString());
            //岗位工资
            double positionWage = Double.valueOf(map.get("g").toString());
            zjlWage.setPositionWage(positionWage);
            Wrapper<ManagerKpi> managerKpiWrapper = new EntityWrapper<>();
            managerKpiWrapper.eq("name",name);
            managerKpiWrapper.eq("month",month);
            List<ManagerKpi> list = managerKpiMapper.selectList(managerKpiWrapper);
            ManagerKpi managerKpi = null;
            if(list.size()>0){
                managerKpi = list.get(0);
            }
            //绩效奖金（绩效工资+提成）没有值 就取kpi的应发绩效
            double performanceBonus = 0;
            if(StringUtils.isNotBlank(map.get("h").toString())){
                performanceBonus = Double.valueOf(map.get("h").toString());
            }else{
                if(managerKpi != null){
                    performanceBonus = managerKpi.getYfPerformance();
                }
            }
            zjlWage.setPerformanceBonus(performanceBonus);
            //专项奖 没有值 就取kpi的应发提成
            double specialBonus = 0;
            if(StringUtils.isNotBlank(map.get("i").toString())){
                specialBonus = Double.valueOf(map.get("i").toString());
            }else{
                if(managerKpi != null){
                    specialBonus = managerKpi.getYfBonus();
                }
            }
            BigDecimal bzxj   =   new   BigDecimal(specialBonus);
            double   zxjl   =   bzxj.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setSpecialBonus(zxjl);
            //年终奖
            double yearEndBonus = 0;
            if(StringUtils.isNotBlank(map.get("j").toString())){
                yearEndBonus = Double.valueOf(map.get("j").toString());
            }
            zjlWage.setYearEndBonus(yearEndBonus);
            //节日费
            double festivalFee = Double.valueOf(map.get("k").toString());
            zjlWage.setFestivalFee(festivalFee);
            //高温补贴
            double highSubsidy = 0;
            if(StringUtils.isNotBlank(map.get("l").toString())){
                highSubsidy = Double.valueOf(map.get("l").toString());
            }
            zjlWage.setHighSubsidy(highSubsidy);
            //通讯补贴
            double correspondenceSubsidy = Double.valueOf(map.get("m").toString());
            zjlWage.setCorrespondenceSubsidy(correspondenceSubsidy);
            //餐费补贴
            double tableMoneySubsidy = Double.valueOf(map.get("n").toString());
            zjlWage.setTableMoneySubsidy(tableMoneySubsidy);
            //交通补贴
            double trafficSubsidy = Double.valueOf(map.get("o").toString());
            zjlWage.setTrafficSubsidy(trafficSubsidy);
            //专项奖（秋营奖励）
            double specialBonusAutumn = Double.valueOf(map.get("p").toString());
            zjlWage.setSpecialBonusAutumn(specialBonusAutumn);
            //其他补扣补退
            double otherSubsidy = Double.valueOf(map.get("q").toString());
            zjlWage.setOtherSubsidy(otherSubsidy);
            //个人养老保险
            double endowmentInsurancePersonal = Double.valueOf(map.get("r").toString());
            zjlWage.setEndowmentInsurancePersonal(endowmentInsurancePersonal);
            //个人缴纳失业保险
            double unenploymentInsurancePersonal = Double.valueOf(map.get("s").toString());
            zjlWage.setUnenploymentInsurancePersonal(unenploymentInsurancePersonal);
            //个人缴纳医疗保险
            double medicarePersonal = Double.valueOf(map.get("t").toString());
            zjlWage.setMedicarePersonal(medicarePersonal);
            //个人缴纳住房公积金
            double reservedFund = Double.valueOf(map.get("u").toString());
            zjlWage.setReservedFund(reservedFund);
            //个税
            double reservedFundTax = Double.valueOf(map.get("v").toString());
            BigDecimal b00 = new BigDecimal(reservedFundTax);
            double f00 = b00.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setReservedFundTax(f00);
            //年终奖个税
            double yearEndBonusTax = Double.valueOf(map.get("w").toString());
            zjlWage.setYearEndBonusTax(yearEndBonusTax);
            //个人其他补交补退
            double otherFeePersonal = 0;
            if(StringUtils.isNotBlank(map.get("x").toString())){
                otherFeePersonal = Double.valueOf(map.get("x").toString());
            }
            zjlWage.setOtherFeePersonal(otherFeePersonal);
            //个人工会费
            double duesPersonal = Double.valueOf(map.get("y").toString());
            zjlWage.setDuesPersonal(duesPersonal);
            double endowmentInsuranceUnit = Double.valueOf(map.get("z").toString());
            zjlWage.setEndowmentInsuranceUnit(endowmentInsuranceUnit);
            double unenploymentInsuranceUnit = Double.valueOf(map.get("aa").toString());
            zjlWage.setUnenploymentInsuranceUnit(unenploymentInsuranceUnit);
            double medicareUnit = Double.valueOf(map.get("ab").toString());
            zjlWage.setMedicareUnit(medicareUnit);
            double employmentInjuryInsuranceUnit = Double.valueOf(map.get("ac").toString());
            zjlWage.setEmploymentInjuryInsuranceUnit(employmentInjuryInsuranceUnit);
            double birthInsuranceUnit = Double.valueOf(map.get("ad").toString());
            zjlWage.setBirthInsuranceUnit(birthInsuranceUnit);
            double illnessInsuranceUnit = Double.valueOf(map.get("ae").toString());
            zjlWage.setIllnessInsuranceUnit(illnessInsuranceUnit);
            double reservedFundUnit = Double.valueOf(map.get("af").toString());
            zjlWage.setReservedFundUnit(reservedFundUnit);
            double laborUnionFeeUnit = Double.valueOf(map.get("ag").toString());
            zjlWage.setLaborUnionFeeUnit(laborUnionFeeUnit);
            double accidentInsuranceUnit = Double.valueOf(map.get("ah").toString());
            zjlWage.setAccidentInsuranceUnit(accidentInsuranceUnit);
            double disabilityInsuranceUnit = Double.valueOf(map.get("ai").toString());
            zjlWage.setDisabilityInsuranceUnit(disabilityInsuranceUnit);
            double otherFeeUnit = Double.valueOf(map.get("aj").toString());
            zjlWage.setOtherFeeUnit(otherFeeUnit);
            String additionMsg = map.get("ak").toString();
            zjlWage.setAdditionMsg(additionMsg);
            double manageFee = Double.valueOf(map.get("al").toString());
            zjlWage.setManageFee(manageFee);
            double endowmentInsurancePersonal2 = 0;
            if(StringUtils.isNotBlank(map.get("am").toString())){
                endowmentInsurancePersonal2 = Double.valueOf(map.get("am").toString());
            }
            zjlWage.setEndowmentInsurancePersonal2(endowmentInsurancePersonal2);
            double unenploymentInsurancePersonal2 = 0;
            if(StringUtils.isNotBlank(map.get("an").toString())){
                unenploymentInsurancePersonal2 = Double.valueOf(map.get("an").toString());
            }
            zjlWage.setUnenploymentInsurancePersonal2(unenploymentInsurancePersonal2);
            double medicarePersonal2 = 0;
            if(StringUtils.isNotBlank(map.get("ao").toString())){
                medicarePersonal2 = Double.valueOf(map.get("ao").toString());
            }
            zjlWage.setMedicarePersonal2(medicarePersonal2);
            double resveredFundPersonal2 = 0;
            if(StringUtils.isNotBlank(map.get("ap").toString())){
                resveredFundPersonal2 = Double.valueOf(map.get("ap").toString());
            }
            zjlWage.setResveredFundPersonal2(resveredFundPersonal2);
            double endowmentInsuranceUnit2 = 0;
            if(StringUtils.isNotBlank(map.get("aq").toString())){
                endowmentInsuranceUnit2 = Double.valueOf(map.get("aq").toString());
            }
            zjlWage.setEndowmentInsurancePersonal2(endowmentInsuranceUnit2);
            double unenploymentInsuranceUnit2 = 0;
            if(StringUtils.isNotBlank(map.get("ar").toString())){
                unenploymentInsuranceUnit2 = Double.valueOf(map.get("ar").toString());
            }
            zjlWage.setUnenploymentInsuranceUnit2(unenploymentInsuranceUnit2);
            double medicareUnit2 = 0;
            if(StringUtils.isNotBlank(map.get("as").toString())){
                medicareUnit2 = Double.valueOf(map.get("as").toString());
            }
            zjlWage.setMedicareUnit2(medicareUnit2);
            double employmentInjuryInsuranceUnit2 = 0;
            if(StringUtils.isNotBlank(map.get("at").toString())){
                employmentInjuryInsuranceUnit2 = Double.valueOf(map.get("at").toString());
            }
            zjlWage.setEmploymentInjuryInsuranceUnit2(employmentInjuryInsuranceUnit2);
            double birthInsuranceUnit2 = 0;
            if(StringUtils.isNotBlank(map.get("au").toString())){
                birthInsuranceUnit2 = Double.valueOf(map.get("au").toString());
            }
            zjlWage.setBirthInsuranceUnit2(birthInsuranceUnit2);
            double illnessInsuranceUnit2 = 0;
            if(StringUtils.isNotBlank(map.get("av").toString())){
                illnessInsuranceUnit2 = Double.valueOf(map.get("av").toString());
            }
            zjlWage.setIllnessInsuranceUnit2(illnessInsuranceUnit2);
            double reservedInsuranceUnit2 = 0;
            if(StringUtils.isNotBlank(map.get("aw").toString())){
                reservedInsuranceUnit2 = Double.valueOf(map.get("aw").toString());
            }
            zjlWage.setReservedInsuranceUnit2(reservedInsuranceUnit2);
            double wage = Double.valueOf(map.get("ax").toString());
            BigDecimal bwage   =   new   BigDecimal(wage);
            double   fwage   =   bwage.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setWage(fwage);
            double wageTax = Double.valueOf(map.get("ay").toString());
            zjlWage.setWageTax(wageTax);
            double wageTaxAfter = 0;
            if(StringUtils.isNotBlank(map.get("az").toString())){
                wageTaxAfter = Double.valueOf(map.get("az").toString());
            }
            zjlWage.setWageTaxAfter(wageTaxAfter);
            double lastYearEndBonus = 0;
            if(StringUtils.isNotBlank(map.get("ba").toString())){
                lastYearEndBonus = Double.valueOf(map.get("ba").toString());
            }
            zjlWage.setLastYearEndBonus(lastYearEndBonus);
            double lastYearEndBonusTax = 0;
            if(StringUtils.isNotBlank(map.get("bb").toString())){
                lastYearEndBonusTax = Double.valueOf(map.get("bb").toString());
            }
            zjlWage.setLastYearEndBonusTax(lastYearEndBonusTax);
            String bankAccount = map.get("bc").toString();
            zjlWage.setBankAccount(bankAccount);
            //是否督导(1是。0不是)  如果是督导 学子公司成本 = 专项奖/0.922  否则为0
            Integer isDuDao = Integer.valueOf(map.get("bd").toString());
            double xzCompanyCast = 0;
            if(isDuDao == 1){
                xzCompanyCast = specialBonus/0.922;
            }
            BigDecimal b0   =   new   BigDecimal(xzCompanyCast);
            double   f0   =   b0.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setXzCompanyCast(f0);
            //应发合计=岗位工资+绩效奖金+专项奖+年终奖+节日费+高温补贴+通讯补贴+餐费补贴+交通补贴+专项奖（秋营奖励）+其他补扣补退
            double totalYf = positionWage+performanceBonus+specialBonus+yearEndBonus+festivalFee+highSubsidy+correspondenceSubsidy+tableMoneySubsidy+trafficSubsidy+specialBonusAutumn+otherSubsidy;
            BigDecimal b1   =   new   BigDecimal(totalYf);
            double   f1   =   b1.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setTotalYf(f1);
            //个人保险小计=养老保险（个人缴费）+失业保险（个人缴费）+医疗保险（个人缴费）
            double totalInsurance =endowmentInsurancePersonal+unenploymentInsurancePersonal+medicarePersonal;
            zjlWage.setTotalInsurance(totalInsurance);
            //个人缴交小计=个人保险小计+公积金（个人缴费）+个税+年终奖个税+个人其他补交补退+个人工会费
            double totalFeePersonal = totalInsurance+reservedFund+f00+yearEndBonusTax+otherFeePersonal+otherFeePersonal;
            BigDecimal b11   =   new   BigDecimal(totalFeePersonal);
            double   f11   =   b11.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setTotalFeePersonal(f11);
            //实发合计=应发合计-个人缴交小计
            double totalSf = totalYf-totalFeePersonal;
            BigDecimal b2   =   new   BigDecimal(totalSf);
            double   f2   =   b2.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setTotalSf(f2);
            //单位缴交小计=单位养老保险+单位失业保险+单位医疗保险+单位工伤保险+单位生育保险+重大疾病保险+单位公积金+工会计提+商业意外险+残保金+单位其他补交补退
            double totalFeeUnit =endowmentInsuranceUnit+unenploymentInsuranceUnit+medicareUnit+employmentInjuryInsuranceUnit+birthInsuranceUnit+illnessInsuranceUnit+reservedFundUnit+laborUnionFeeUnit+accidentInsuranceUnit+disabilityInsuranceUnit+otherFeeUnit;
            zjlWage.setTotalFeeUnit(totalFeeUnit);
            //总个人人工成本合计=单位缴交小计+应发合计
            double totalCastPersonal = totalFeeUnit + totalYf;
            BigDecimal b3   =   new   BigDecimal(totalCastPersonal);
            double   f3   =   b3.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setTotalCastPersonal(f3);
            //单位总成本（含支出税点）=(总个人人工成本合计+邮电人才服务管理费)/0.922
            double totalCastUnit = (totalCastPersonal+manageFee)/0.922;
            BigDecimal b4   =   new   BigDecimal(totalCastUnit);
            double   f4   =   b4.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setTotalCastUnit(f4);
            //合并计税=个人缴纳养老保险2+个人缴纳失业保险2+个人缴纳医疗保险2+个人缴纳住房公积金2+单位养老保险2+单位失业保险2+单位医疗保险2+单位工伤保险2+单位生育保险2+重大疾病保险企业缴纳2+单位住房公积金2
            double totalInsuranceUnit2 = endowmentInsurancePersonal2+unenploymentInsurancePersonal2+medicarePersonal2
                    +resveredFundPersonal2+endowmentInsuranceUnit2+unenploymentInsuranceUnit2+medicareUnit2+employmentInjuryInsuranceUnit2
                    +birthInsuranceUnit+illnessInsuranceUnit2+reservedInsuranceUnit2;
            zjlWage.setTotalInsuranceUnit2(totalInsuranceUnit2);
            //督导成本=单位总成本（含支出税点）- 学子公司成本
            double managerCast = totalCastUnit-xzCompanyCast;
            BigDecimal b5 = new BigDecimal(managerCast);
            double f5 = b5.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            zjlWage.setManagerCast(f5);

            Integer integer = zjlWageMapper.insert(zjlWage);
            if (integer == 1) {
                number++;
            } else {
                error.append("第" + (i + 1) + "行的更新失败,");
            }
        }
        error.append("成功更新" + number + "条数据！");
        return ResponseData.success(error.toString(), "导入完成");
    }
}
