package com.ssm.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.github.pagehelper.PageInfo;
import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.response.PageResponse;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.entity.*;
import com.ssm.manage.excelEntity.ExcelRepayList;
import com.ssm.manage.query.*;
import com.ssm.manage.response.RepayListResponse;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Api(value="还款controller",tags={"还款相关接口"})
@RestController
@RequestMapping("/demay/ssm/repay")
@Slf4j
public class SsmRepayController {
    @Autowired
    private SsmRepayService ssmRepayService;

    @Autowired
    private SsmBaseStoreService ssmBaseStoreService;

    @Autowired
    private SsmPayService ssmPayService;

    @Autowired
    private SsmSalesmanService ssmSalesmanService;

    @Autowired
    private SsmRepayTradeService ssmRepayTradeService;

    @ApiOperation(value = "分页查询  门店端-还款单-分页查询还款单",httpMethod = "POST",response = PageResponse.class)
    @RequestMapping("/page")
    public PageResponse selectPage(@RequestBody RepayListRequest repayListRequest, HttpSession session){
        PageResponse<RepayListResponse> pageResponse = new PageResponse<>();
        PageInfo<RepayListResponse> pageInfo = new PageInfo<>();
        repayListRequest.setStoreId(SessionHelp.getStoreId(session));
        try {
            pageInfo = ssmRepayService.selectPage(repayListRequest);
        }catch (Exception e){
            log.error("SsmRepayController.selectPage",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }
    @Autowired
    private SsmSysRoleStoreService ssmSysRoleStoreService;

    @ApiOperation(value = "分页查询  门店端-还款单-分页查询还款单",httpMethod = "POST",response = PageResponse.class)
    @RequestMapping("/pageNew")
    public PageResponse selectPageNew(@RequestBody RepayListRequest repayListRequest, HttpSession session){
        PageResponse<RepayListResponse> pageResponse = new PageResponse<>();
        PageInfo<RepayListResponse> pageInfo = new PageInfo<>();
        List<Long> listStoreId=new ArrayList<>();
        if(repayListRequest.getStoreId() == null && (null == repayListRequest.getStoreList() || repayListRequest.getStoreList().size() == 0)){
            //自动查询
            repayListRequest.setSelectType(0);
            repayListRequest.setStoreId(SessionHelp.getStoreId(session));
            SysRoleStoreRequest sysStoreRole = new SysRoleStoreRequest();
            sysStoreRole.setRoleId(repayListRequest.getRoleId());
            PageInfo<SysRoleStore> sysRoleStorePageInfo = ssmSysRoleStoreService.selectPage(sysStoreRole);
            List<Long> collect = sysRoleStorePageInfo.getList().stream().map(item -> item.getStoreId()).collect(Collectors.toList());
            repayListRequest.setStoreList(collect);
            listStoreId.add(SessionHelp.getStoreId(session));
            repayListRequest.setStoreList(listStoreId);
        }else{
            //指定查询
            repayListRequest.setSelectType(0);
        }

        try {
            pageInfo = ssmRepayService.selectPageNew(repayListRequest);
        }catch (Exception e){
            log.error("SsmRepayController.selectPage",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @ApiOperation(value = "分页查询  门店端-还款单-分页查询还款单",httpMethod = "POST",response = PageResponse.class)
    @RequestMapping("/pageDetail")
    public PageResponse pageDetail(@RequestBody RepayListRequest repayListRequest, HttpSession session){
        PageResponse<RepayListResponse> pageResponse = new PageResponse<>();
        PageInfo<RepayListResponse> pageInfo = new PageInfo<>();
        try {
            pageInfo = ssmRepayService.pageDetail(repayListRequest);
        }catch (Exception e){
            log.error("SsmRepayController.selectPage",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }




    @ApiOperation(value = "还款单添加  (门店端-还款单-还款单添加)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/add")
//    @RequestMapping("/addPromotionRecharge")
    public GenericResponse add(@RequestBody RepayListRequest repayListRequest, HttpSession session) {
        GenericResponse genericResponse = new GenericResponse();
        Long storeId = SessionHelp.getStoreId(session);
        String storeName = SessionHelp.getStoreName(session);
        String staffPhone = SessionHelp.getLoginAccount(session);
        repayListRequest.setStoreId(storeId);
        repayListRequest.setStoreName(storeName);
        repayListRequest.setStaffPhone(staffPhone);
        //添加高管的当前单据门店信息
        StoreRequest storeRequest = new StoreRequest();
        storeRequest.setId(SessionHelp.getStoreId(session));
        BaseStore baseStore1 = ssmBaseStoreService.selectOne(storeRequest);
        List<RepayTradeRequest> repayTradeLists = repayListRequest.getRepayTradeLists();
        for (RepayTradeRequest repayTradeList : repayTradeLists) {
            List<Salesman> salesmens = repayTradeList.getSalesmens();
            for (Salesman salesmen : salesmens) {
                salesmen.setStoreNum(baseStore1.getStoreNum());
                salesmen.setStoreName(baseStore1.getStoreName());
                salesmen.setStoreIdOrder(baseStore1.getId());
            }
        }
        int i = 0;
        try {
            i = ssmRepayService.addRepay(repayListRequest);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmRepayController.add:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "还款单添加  (门店端-还款单-还款单添加)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/addPromotionRecharge")
//    @RequestMapping("/add")
    public GenericResponse addPromotionRecharge(@RequestBody RepayListRequest repayListRequest, HttpSession session) {
        GenericResponse genericResponse = new GenericResponse();
        Long storeId = SessionHelp.getStoreId(session);
        String storeName = SessionHelp.getStoreName(session);
        String staffPhone = SessionHelp.getLoginAccount(session);
        repayListRequest.setStoreId(storeId);
        repayListRequest.setStoreName(storeName);
        repayListRequest.setStaffPhone(staffPhone);
        //添加高管的当前单据门店信息
        StoreRequest storeRequest = new StoreRequest();
        storeRequest.setId(SessionHelp.getStoreId(session));
        BaseStore baseStore1 = ssmBaseStoreService.selectOne(storeRequest);
        List<RepayTradeRequest> repayTradeLists = repayListRequest.getRepayTradeLists();
        for (RepayTradeRequest repayTradeList : repayTradeLists) {
            List<Salesman> salesmens = repayTradeList.getSalesmens();
            for (Salesman salesmen : salesmens) {
                salesmen.setStoreNum(baseStore1.getStoreNum());
                salesmen.setStoreName(baseStore1.getStoreName());
                salesmen.setStoreIdOrder(baseStore1.getId());
            }
        }
        int i = 0;
        try {
            i = ssmRepayService.addPromotionRecharge(repayListRequest);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmRepayController.add:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "还款单作废  (门店端-还款单-还款单作废)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/cancel")
//    @RequestMapping("/cancelPromotionRecharge")
    public GenericResponse cancel(@RequestBody RepayListRequest repayListRequest, HttpSession session) {
        GenericResponse genericResponse = new GenericResponse();
        Long storeId = SessionHelp.getStoreId(session);
        String storeName = SessionHelp.getStoreName(session);
        String staffPhone = SessionHelp.getLoginAccount(session);
        if(repayListRequest.getStoreId()==null||repayListRequest.getStoreName()==null){
            repayListRequest.setStoreId(storeId);
            repayListRequest.setStoreName(storeName);
        }
        repayListRequest.setStaffPhone(staffPhone);
        int i = 0;
        try {
            i = ssmRepayService.cancel(repayListRequest);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmRepayController.cancel:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i == 8){
            genericResponse.setCodeAndMsg(ResponseCode.IS_INSUFFICIENT,"疗程账户剩余次数");
        }else if (i ==9){
            genericResponse.setCodeAndMsg(ResponseCode.IS_INSUFFICIENT,"疗程账户剩余可用次数");
        }else if (i > 0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "还款单作废  (门店端-还款单-还款单作废)",httpMethod = "POST",response = GenericResponse.class)
//    @RequestMapping("/cancel")
    @RequestMapping("/cancelPromotionRecharge")
    public GenericResponse cancelPromotionRecharge(@RequestBody RepayListRequest repayListRequest, HttpSession session) {
        GenericResponse genericResponse = new GenericResponse();
        Long storeId = SessionHelp.getStoreId(session);
        String storeName = SessionHelp.getStoreName(session);
        String staffPhone = SessionHelp.getLoginAccount(session);
        if(repayListRequest.getStoreId()==null||repayListRequest.getStoreName()==null){
            repayListRequest.setStoreId(storeId);
            repayListRequest.setStoreName(storeName);
        }
        repayListRequest.setStaffPhone(staffPhone);
        int i = 0;
        try {
            i = ssmRepayService.cancelPromotionRecharge(repayListRequest);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmRepayController.cancel:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i == 8){
            genericResponse.setCodeAndMsg(ResponseCode.IS_INSUFFICIENT,"疗程账户剩余次数");
        }else if (i ==9){
            genericResponse.setCodeAndMsg(ResponseCode.IS_INSUFFICIENT,"疗程账户剩余可用次数");
        }else if (i > 0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

//    @ApiOperation(value = "还款单修改业务员  (门店端-还款单-还款单修改业务员)",httpMethod = "POST",response = GenericResponse.class)
//    @RequestMapping("/updateStaff")
//    public GenericResponse updateStaff(@RequestBody RepayListRequest repayListRequest, HttpSession session) {
//        GenericResponse genericResponse = new GenericResponse();
//        Long storeId = SessionHelp.getStoreId(session);
//        String storeName = SessionHelp.getStoreName(session);
//        String staffPhone = SessionHelp.getLoginAccount(session);
//        repayListRequest.setStoreId(storeId);
//        repayListRequest.setStoreName(storeName);
//        repayListRequest.setStaffPhone(staffPhone);
//        int i = 0;
//        try {
//            i = ssmRepayService.updateStaff(repayListRequest);
//        }catch (SmsException e){
//            genericResponse.setCodeAndMsg(e);
//            return genericResponse;
//        }catch (Exception e){
//            log.error("SsmRepayController.updateStaff:",e);
//            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
//            return genericResponse;
//        }
//        if (i > 0){
//            genericResponse.setCodeAndMsg(ResponseCode.OK);
//        }
//        return genericResponse;
//    }


    @ApiOperation(value = "还款单修改业务员  (门店端-还款单-还款单修改业务员)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/updateStaff")
    public GenericResponse updateStaff(@RequestBody List<RepayTradeRequest> repayTradeRequest, HttpSession session) {
        GenericResponse genericResponse = new GenericResponse();
        Long storeId = SessionHelp.getStoreId(session);
//        String storeName = SessionHelp.getStoreName(session);
//        repayTradeRequest.setStoreId(storeId);
//        repayTradeRequest.setStoreName(storeName);
        int i = 0;
        try {
            i = ssmRepayTradeService.updateStaff(repayTradeRequest);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmRepayController.updateStaff:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }
    @ApiOperation(value = "单据导出", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/repay/exportachis")
    public void exportachis(@RequestBody RepayListRequest repayListRequest, HttpSession session) {
        // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
        // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list
        ExcelWriter excelWriter = null;
        OutputStream out = null;
//        courseListRequest.setStoreId(SessionHelp.getStoreId(session));
        try {
            String fileName = "projectType";
            HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1") + ".xlsx");
            out = response.getOutputStream();
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config/repayList.xlsx");
//            BeanUtils.copyProperties(projectTypeRequest, baseProjectType);
            List<ExcelRepayList> excelBaseProjectTypeList = new ArrayList<>();
            List<RepayTradeList> list = ssmRepayTradeService.selectListNew(repayListRequest);
            if(list!=null && list.size()>0) {
                List<RepayList> repayLists = ssmRepayService.selectNew(repayListRequest);
//            salesmen = ssmSalesmanService.selectList(salesman);
                //所有门店
                List<BaseStore> select = ssmBaseStoreService.select(null);
                //所有项目id
//            List<Long> projectIds = list.stream().filter(courseList -> courseList.getProjctId() != null).map(CourseList::getProjctId).collect(Collectors.toList());
//            List<BaseProject> projectList = ssmProjectService.selectList(projectIds);
                //所有单据号
                List<String> courseNums = list.stream().map(RepayTradeList::getRepayNum).collect(Collectors.toList());
                List<PayList> payListList = ssmPayService.selectList(courseNums);
                //查询管理层和高管
                List<Long> courseIds = list.stream().map(RepayTradeList::getId).collect(Collectors.toList());
                List<Salesman> salesmanList = ssmSalesmanService.selectList(courseIds);
                for (RepayTradeList executives : list) {
                    ExcelRepayList excelBaseProjectType = new ExcelRepayList();
                    BeanUtils.copyProperties(executives, excelBaseProjectType);
                    excelBaseProjectType.setPayType("");
                    for (RepayList repayList : repayLists) {
                        if (repayList.getRepayNum().equals(excelBaseProjectType.getRepayNum())) {
                            if (repayList.getIsCancel() == 0) {
                                excelBaseProjectType.setIsCancelNew("正常");
                            } else {
                                excelBaseProjectType.setIsCancelNew("作废");
                            }
                        }
                    }
                    //设置门店编码
                    for (BaseStore baseStore : select) {
                        if (baseStore.getId() == excelBaseProjectType.getStoreId() || baseStore.getId().equals(excelBaseProjectType.getStoreId())) {
                            excelBaseProjectType.setStoreNum(baseStore.getStoreNum());
                        }
                    }
                    //设置支付方式
                    for (PayList payList : payListList) {
                        if (payList.getDocId().equals(executives.getRepayNum())) {
                            excelBaseProjectType.setPayType(excelBaseProjectType.getPayType() + "-" + payList.getPayName() + ":" + payList.getPayMoney() + "元-");
                        }
                    }
                    //设置高管和管理层
                    List<Salesman> guanliceng = salesmanList.stream().filter(item -> (item.getOrderId().equals(executives.getId().toString())) && (item.getStaffType() == 1 || item.getStaffType().equals("1"))).collect(Collectors.toList());
                    List<Salesman> gaoguan = salesmanList.stream().filter(item -> (item.getOrderId().equals(executives.getId().toString())) && (item.getStaffType() == 0 || item.getStaffType().equals("0"))).collect(Collectors.toList());
                    if (guanliceng != null && guanliceng.size() > 0) {
                        for (int i = 0; i < guanliceng.size(); i++) {
                            if (i == 0) {
                                excelBaseProjectType.setSalmenOneNumber(guanliceng.get(i).getBrandNumber());
                                excelBaseProjectType.setSalmenOneName(guanliceng.get(i).getStaffName());
                                excelBaseProjectType.setSalmenOneRatio(guanliceng.get(i).getRatio().toString());

                            }
                            if (i == 1) {
                                excelBaseProjectType.setSalmenTwoNumber(guanliceng.get(i).getBrandNumber());
                                excelBaseProjectType.setSalmenTwoName(guanliceng.get(i).getStaffName());
                                excelBaseProjectType.setSalmenTwoRatio(guanliceng.get(i).getRatio().toString());
                            }
                            if (i == 2) {
                                excelBaseProjectType.setSalmenThreeNumber(guanliceng.get(i).getBrandNumber());
                                excelBaseProjectType.setSalmenThreeName(guanliceng.get(i).getStaffName());
                                excelBaseProjectType.setSalmenThreeRatio(guanliceng.get(i).getRatio().toString());
                            }
                            if (i == 3) {
                                excelBaseProjectType.setSalmenFourNumber(guanliceng.get(i).getBrandNumber());
                                excelBaseProjectType.setSalmenFourName(guanliceng.get(i).getStaffName());
                                excelBaseProjectType.setSalmenFourRatio(guanliceng.get(i).getRatio().toString());
                            }
                        }
                    }
                    if (gaoguan != null && gaoguan.size() > 0) {
                        for (int i = 0; i < gaoguan.size(); i++) {
                            if (i == 0) {
                                excelBaseProjectType.setSalmensOneNumber(gaoguan.get(i).getBrandNumber());
                                excelBaseProjectType.setSalmensOneName(gaoguan.get(i).getStaffName());
                                excelBaseProjectType.setSalmensOneRatio(gaoguan.get(i).getRatio().toString());
                            }
                            if (i == 1) {
                                excelBaseProjectType.setSalmensTwoNumber(gaoguan.get(i).getBrandNumber());
                                excelBaseProjectType.setSalmensTwoName(gaoguan.get(i).getStaffName());
                                excelBaseProjectType.setSalmensTwoRatio(gaoguan.get(i).getRatio().toString());
                            }
                            if (i == 2) {
                                excelBaseProjectType.setSalmensThreeNumber(gaoguan.get(i).getBrandNumber());
                                excelBaseProjectType.setSalmensThreeName(gaoguan.get(i).getStaffName());
                                excelBaseProjectType.setSalmensThreeRatio(gaoguan.get(i).getRatio().toString());
                            }
                            if (i == 3) {
                                excelBaseProjectType.setSalmensFourNumber(gaoguan.get(i).getBrandNumber());
                                excelBaseProjectType.setSalmensFourName(gaoguan.get(i).getStaffName());
                                excelBaseProjectType.setSalmensFourRatio(gaoguan.get(i).getRatio().toString());
                            }
                        }
                    }
                    //设置销售人员业绩和提成
                    BigDecimal achievementAmount = excelBaseProjectType.getAchievementAmount().add(excelBaseProjectType.getCardAchievementAmount());
                    BigDecimal commissionAmount = excelBaseProjectType.getCommissionAmount().add(excelBaseProjectType.getCardCommissionAmount());
                    BigDecimal hundred = new BigDecimal("100");
                    if (excelBaseProjectType.getSaleOneStaffId() != null) {
                        excelBaseProjectType.setSaleOneAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleOneRatio().divide(hundred)));
                        excelBaseProjectType.setSaleOneCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleOneRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getSaleTwoStaffId() != null) {
                        excelBaseProjectType.setSaleTwoAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleTwoRatio().divide(hundred)));
                        excelBaseProjectType.setSaleTwoCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleTwoRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getSaleThreeStaffId() != null) {
                        excelBaseProjectType.setSaleThreeAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleThreeRatio().divide(hundred)));
                        excelBaseProjectType.setSaleThreeCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleThreeRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getSaleFourStaffId() != null) {
                        excelBaseProjectType.setSaleFourAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleFourRatio().divide(hundred)));
                        excelBaseProjectType.setSaleFourCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleFourRatio().divide(hundred)));
                    }

                    if (excelBaseProjectType.getSaleFiveStaffId() != null) {
                        excelBaseProjectType.setSaleFiveAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleFiveRatio().divide(hundred)));
                        excelBaseProjectType.setSaleFiveCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleFiveRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getSaleSixStaffId() != null) {
                        excelBaseProjectType.setSaleSixAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleSixRatio().divide(hundred)));
                        excelBaseProjectType.setSaleSixCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleSixRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getSaleSevenStaffId() != null) {
                        excelBaseProjectType.setSaleSevenAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleSevenRatio().divide(hundred)));
                        excelBaseProjectType.setSaleSevenCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleSevenRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getSaleEightStaffId() != null) {
                        excelBaseProjectType.setSaleEightAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleEightRatio().divide(hundred)));
                        excelBaseProjectType.setSaleEightCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleEightRatio().divide(hundred)));
                    }
//                if(excelBaseProjectType.getSaleFiveStaffId()!=null){
//                    excelBaseProjectType.setSaleFiveAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleFiveRatio().divide(hundred)));
//                    excelBaseProjectType.setSaleFiveCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleFiveRatio().divide(hundred)));
//                }
//                if(excelBaseProjectType.getSaleSixStaffId()!=null){
//                    excelBaseProjectType.setSaleSixAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleSixRatio().divide(hundred)));
//                    excelBaseProjectType.setSaleSixCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleSixRatio().divide(hundred)));
//                }
//                if(excelBaseProjectType.getSaleSevenStaffId()!=null){
//                    excelBaseProjectType.setSaleSevenAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleSevenRatio().divide(hundred)));
//                    excelBaseProjectType.setSaleSevenCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleSevenRatio().divide(hundred)));
//                }
//                if(excelBaseProjectType.getSaleEightStaffId()!=null){
//                    excelBaseProjectType.setSaleEightAchievementAmount(achievementAmount.multiply(excelBaseProjectType.getSaleEightRatio().divide(hundred)));
//                    excelBaseProjectType.setSaleEightCommissionAmount(commissionAmount.multiply(excelBaseProjectType.getSaleEightRatio().divide(hundred)));
//                }


                    excelBaseProjectTypeList.add(excelBaseProjectType);
                }
            }
            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
            //EasyExcel.write(out, LiveRoomData.class).sheet("模板").doWrite(list);
            excelWriter = EasyExcel.write(out).withTemplate(inputStream).build();
            //FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
            WriteSheet writeSheet = EasyExcel.writerSheet().build();
            excelWriter.fill(excelBaseProjectTypeList, writeSheet);
            out.flush();
        } catch (Exception e) {
            log.error("SsmProjectTypeController.export:",e);
        } finally {
            //destFile.delete();
            // 别忘记关闭流
            excelWriter.finish();
        }
    }


}
