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.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.response.PageResponse;
import com.ssm.manage.utils.LogExecutionTime;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.core.utils.ChuangLanBeanSmsUtil;
import com.ssm.core.utils.FtpUtils;
import com.ssm.manage.entity.*;
import com.ssm.manage.excelEntity.ExcelCashListNew;
import com.ssm.manage.query.*;
import com.ssm.manage.response.CashListResponse;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.*;
import com.ssm.manage.utils.Constant;
import com.ssm.manage.utils.DateUtils;
import com.ssm.util.RedisClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Api(value="收银controller",tags={"门店收银相关接口"})
@RestController
@RequestMapping("/demay/ssm/cash")
@Slf4j
public class SsmCashController {
    @Autowired
    private SsmCashService ssmCashService;

    @Autowired
    private ChuangLanBeanSmsUtil chuangLanBeanSmsUtil;
    @Autowired
    private SsmCashSignatureService ssmCashSignatureService;

    @Autowired
    private SmsFixService smsFixService;

    @Autowired
    private SsmBaseStoreService ssmBaseStoreService;

    @Autowired
    private SsmRechargeAccountService ssmRechargeAccountService;

    @Autowired
    private SsmCourseAccountService ssmCourseAccountService;

    @Autowired
    private SsmRechargeTypeSevice ssmRechargeTypeSevice;

    @Autowired
    private SsmProjectService ssmProjectService;

    @Autowired
    private SsmPayService ssmPayService;

    @Autowired
    private SsmSalesmanService ssmSalesmanService;

    @Autowired
    private SsmAccountTradeRecordService ssmAccountTradeRecordService;

    @Autowired
    private RedisClient<String> redisClient;


    //引入消息发送API
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//    private static final String CASH_TOPIC_EXCHANGE = "cash_exchange";
//    private static final String CASH_ROUKEY = "cash.sendSms";
//本接口只是验证我到底发布成功没有
    @RequestMapping("/success")
    public PageResponse success(){
        PageResponse pageResponse = new PageResponse<>();
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    @ApiOperation(value = "查询收银服务单收款列表  (门店端-服务单-查询收银服务单收款列表)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/cashListByDocNum")
    public PageResponse cashListByDocNum(@RequestBody CashListRequest cashListRequest, HttpSession session){
        PageResponse<CashListResponse> pageResponse = new PageResponse<>();
        PageInfo<CashListResponse> pageInfo = new PageInfo<>();
        Long storeId=cashListRequest.getStoreId();
        if(storeId==null){

            storeId = SessionHelp.getStoreId(session);
        }
        List<Long> listStoreId=new ArrayList<>();

        cashListRequest.setStoreListboolean(1);
        if( cashListRequest.getStoreList()!=null&&cashListRequest.getStoreList().size()>0)
            cashListRequest.setStoreListboolean(0);

        if(null == cashListRequest.getStoreList()|| cashListRequest.getStoreList().size()<=0){
            cashListRequest.setSelectType(1);
            cashListRequest.setStoreId(storeId);
            listStoreId.add(storeId);
            cashListRequest.setStoreList(listStoreId);
        }else{
            cashListRequest.setSelectType(0);
        }
        if(cashListRequest.getCashNum()!=null) {
            String docnum = cashListRequest.getCashNum();
            String substring = docnum.substring(docnum.length() - 11, docnum.length() - 5);
            cashListRequest.setSelectDate(substring);
            System.out.println("substring = " + substring);
        }
        try {
            pageInfo = ssmCashService.selectCashListNew(cashListRequest);
        }catch (SmsException e){
            pageResponse.setCodeAndMsg(e);
            return pageResponse;
        }catch (Exception e){
            log.error("SsmCashController.selectCashList:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }


    @ApiOperation(value = "查询收银服务单列表  (门店端-服务单-查询收银服务单列表)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/page")
    public PageResponse selectPage(@RequestBody CashListRequest cashListRequest, HttpSession session){
        PageResponse<CashListResponse> pageResponse = new PageResponse<>();
        PageInfo<CashListResponse> pageInfo = new PageInfo<>();
        Long storeId = SessionHelp.getStoreId(session);
        if(SessionHelp.getStoreId(session)==null){
            pageResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return pageResponse;
        }
        cashListRequest.setStoreId(storeId);
        try {
            pageInfo = ssmCashService.selectPage(cashListRequest);
        }catch (Exception e){
            log.error("SsmCashController.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("/cashList")
    public PageResponse selectCashList(@RequestBody CashListRequest cashListRequest, HttpSession session){
        PageResponse<CashListResponse> pageResponse = new PageResponse<>();
        PageInfo<CashListResponse> pageInfo = new PageInfo<>();
        Long storeId = SessionHelp.getStoreId(session);
        if(SessionHelp.getStoreId(session)==null){
            pageResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return pageResponse;
        }
        if(null == cashListRequest.getStoreId()){
            cashListRequest.setStoreId(storeId);
        }

        try {
            pageInfo = ssmCashService.selectCashList(cashListRequest);
        }catch (SmsException e){
            pageResponse.setCodeAndMsg(e);
            return pageResponse;
        }catch (Exception e){
            log.error("SsmCashController.selectCashList:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @ApiOperation(value = "查询收银服务单收款列表  (门店端-服务单-查询收银服务单收款列表)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/cashListNew")
    @LogExecutionTime
    public PageResponse selectCashListNew(@RequestBody CashListRequest cashListRequest, HttpSession session){
        PageResponse<CashListResponse> pageResponse = new PageResponse<>();
        PageInfo<CashListResponse> pageInfo = new PageInfo<>();
        Long storeId = SessionHelp.getStoreId(session);
        if(SessionHelp.getStoreId(session)==null){
            pageResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return pageResponse;
        }
        List<Long> listStoreId=new ArrayList<>();

        cashListRequest.setStoreListboolean(1);
        if( cashListRequest.getStoreList()!=null&&cashListRequest.getStoreList().size()>0)
            cashListRequest.setStoreListboolean(0);

        if(null == cashListRequest.getStoreList()|| cashListRequest.getStoreList().size()<=0){
            cashListRequest.setSelectType(1);
            cashListRequest.setStoreId(storeId);
            listStoreId.add(storeId);
            cashListRequest.setStoreList(listStoreId);
        }else{
            cashListRequest.setSelectType(0);
        }

        try {
            pageInfo = ssmCashService.selectCashListNew(cashListRequest);
        }catch (SmsException e){
            pageResponse.setCodeAndMsg(e);
            return pageResponse;
        }catch (Exception e){
            log.error("SsmCashController.selectCashList:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @ApiOperation(value = "跟据交易记录和业绩表数据查询收银服务单收款列表  (门店端-服务单-查询收银服务单收款列表)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/pageDetail")
    public PageResponse cashListDetail(@RequestBody CashListRequest cashListRequest, HttpSession session){
        PageResponse<CashListResponse> pageResponse = new PageResponse<>();
        PageInfo<CashListResponse> pageInfo = new PageInfo<>();
        try {
            pageInfo = ssmCashService.cashListDetail(cashListRequest);
        }catch (SmsException e){
            pageResponse.setCodeAndMsg(e);
            return pageResponse;
        }catch (Exception e){
            log.error("SsmCashController.selectCashList:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @ApiOperation(value = "查询收银服务单收款列表  (门店端-服务单-查询收银服务单收款列表)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/cashLists")
    public PageResponse selectCashLists(@RequestBody CashListRequest cashListRequest, HttpSession session){
        PageResponse<CashListResponse> pageResponse = new PageResponse<>();
        PageInfo<CashListResponse> pageInfo = new PageInfo<>();
        if(SessionHelp.getStoreId(session)==null){
            pageResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return pageResponse;
        }
        Long storeId = SessionHelp.getStoreId(session);
        cashListRequest.setStoreId(storeId);
        try {
            pageInfo = ssmCashService.selectCashLists(cashListRequest);
        }catch (SmsException e){
            pageResponse.setCodeAndMsg(e);
            return pageResponse;
        }catch (Exception e){
            log.error("SsmCashController.selectCashList:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }


    @ApiOperation(value = "服务单收银  (门店端-服务单-服务单收银)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/doCash")
    public GenericResponse doCash(MultipartFile file, @RequestParam String cashListRequestList, HttpSession session) {
        GenericResponse genericResponse = new GenericResponse();
        CashSignatureFile cashSignatureFile = new CashSignatureFile();
        if (null != file) {
            String fileName = file.getOriginalFilename();//获取文件名
            String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());//获取文件后缀
            String saveName = DateUtils.getDateNowStr() + "." + suffix;//将文件名用时间重命名
            String path = Constant.filePath + "/" + SessionHelp.getStoreId(session);//文件上传路径

            cashSignatureFile.setFileName(saveName);
            cashSignatureFile.setFilePath(path);
            InputStream inputStream = null;
            boolean b = false;
            try {
                inputStream = file.getInputStream();
                b = new FtpUtils().uploadFile(path, saveName, inputStream);
            } catch (IOException e) {
                log.error("SsmCashController.doCash:", e);
                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
                return genericResponse;
            }
            if (!b){
                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
                return genericResponse;
            }
        }

        if(SessionHelp.getStoreId(session)==null){
            genericResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return genericResponse;
        }
        Long storeId = SessionHelp.getStoreId(session);
        String storeName = SessionHelp.getStoreName(session);
        String staffPhone = SessionHelp.getLoginAccount(session);
        List<CashListRequest> cashListRequests = JSON.parseArray(cashListRequestList,CashListRequest.class);
        List<AccountTradeRecord> list = new ArrayList<>();
        try {
            list = ssmCashService.doCash(cashListRequests, staffPhone, cashSignatureFile);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmCashController.doCash:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if(cashListRequests.get(0).getIsSendSms()==1) {
            if (list.size() > 0) {
                BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeId);
                for (AccountTradeRecord accountTradeRecord : list) {
                    //发送短信 充值卡支付
                    if (Constant.account_type_recharge_consume.equals(accountTradeRecord.getAccountType())) {
                        //设置短信账户 发送 否则不发送
                        if (StringUtils.isNotBlank(baseStore.getSmsAccount()) && null != baseStore.getMessagingPlatform()) {
                            try {
                                chuangLanBeanSmsUtil.sendCashByRechargeSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getAccountSpendMoney(), accountTradeRecord.getAccountConsumeMoney());
                            } catch (IOException e) {
                                log.error("SsmCashController.doCash:", e);
                            } catch (SmsException e) {
                                log.error("SsmCashController.doCash:", e);
                                genericResponse.setCodeAndMsg(e);
                            }
                        }
                    } else if (Constant.account_type_project_consume.equals(accountTradeRecord.getAccountType())) {//疗程卡支付
                        //设置短信账户 发送 否则不发送
                        if (StringUtils.isNotBlank(baseStore.getSmsAccount()) && null != baseStore.getMessagingPlatform()) {
                            try {
//                            chuangLanBeanSmsUtil.sendSLStoreCashProjectPaySms(baseStore, accountTradeRecord.getMemberName(), accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
                                chuangLanBeanSmsUtil.sendCashByCourseSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
                            } catch (IOException e) {
                                log.error("SsmCashController.doCash:", e);
                            } catch (SmsException e) {
                                log.error("SsmCashController.doCash:", e);
                                genericResponse.setCodeAndMsg(e);
                            }
                        }
                    }

                }

            }
        }else {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }

        return genericResponse;
    }

    @ApiOperation(value = "服务单收银作废  (门店端-服务单-服务单收银作废)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/cancel")
    public GenericResponse cancel(@RequestBody List<CashListRequest> cashListRequestList, HttpSession session) {
        GenericResponse genericResponse = new GenericResponse();
        if(SessionHelp.getStoreId(session)==null){
            genericResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return genericResponse;
        }
        String staffPhone = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmCashService.cancel(cashListRequestList, staffPhone);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmCashController.cancel:",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<CashListRequest> cashListRequestList,HttpSession session) {
        GenericResponse genericResponse = new GenericResponse();
        if(SessionHelp.getStoreId(session)==null){
            genericResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return genericResponse;
        }
        Long storeId = SessionHelp.getStoreId(session);
        int i = 0;
        try {
            i = ssmCashService.updateStaff(cashListRequestList, storeId);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmCashController.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("/addCashList")
    public GenericResponse addCashList(MultipartFile file,@RequestParam String cashListRequestList,HttpSession session){
        GenericResponse genericResponse = new GenericResponse<>();
        CashSignatureFile cashSignatureFile = new CashSignatureFile();
        if(SessionHelp.getStoreId(session)==null){
            genericResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return genericResponse;
        }

        if (null != file) {
            String fileName = file.getOriginalFilename();//获取文件名
            String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());//获取文件后缀
            String saveName = DateUtils.getDateNowStr() + "." + suffix;//将文件名用时间重命名
            String path = Constant.filePath + "/" + SessionHelp.getStoreId(session);//文件上传路径

            cashSignatureFile.setFileName(saveName);
            cashSignatureFile.setFilePath(path);
            InputStream inputStream = null;
            boolean b = false;
            try {
                inputStream = file.getInputStream();
                b = new FtpUtils().uploadFile(path, saveName, inputStream);
            } catch (IOException e) {
                log.error("SsmCashController.addCashList:", e);
                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
                return genericResponse;
            }
            if (!b){
                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
                return genericResponse;
            }
        }
//        System.out.println(cashListRequestList);
//        List<CashListRequest> userList  = JSON.parseObject(cashListRequestList, new TypeReference<List<CashListRequest>>(){});
        List<CashListRequest> cashListRequests = JSON.parseArray(cashListRequestList.trim(),CashListRequest.class);

        Long storeId = SessionHelp.getStoreId(session);
        String storeName = SessionHelp.getStoreName(session);
        String phone = SessionHelp.getLoginAccount(session);
        List<AccountTradeRecord> list = new ArrayList<>();
        try {
            list = ssmCashService.addCashList(cashListRequests,storeId,storeName,phone, cashSignatureFile);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmCashController.addCashList:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }

        genericResponse.setCodeAndMsg(ResponseCode.OK);

        if (list.size() > 0) {
            BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeId);
            for (AccountTradeRecord accountTradeRecord : list) {
                //发送短信 充值卡支付
                if (Constant.account_type_recharge_consume.equals(accountTradeRecord.getAccountType())) {
                    if (StringUtils.isNotBlank(baseStore.getSmsAccount())) {
                        try {
                            chuangLanBeanSmsUtil.sendCashByRechargeSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getAccountSpendMoney(), accountTradeRecord.getAccountRestMoney());
                        } catch (IOException e) {
                            log.error("SsmCashController.addCashList:", e);
                        } catch (SmsException e) {
                            log.error("SsmCashController.addCashList:", e);
                            genericResponse.setCodeAndMsg(e);
                        }
                    }
                //疗程卡支付
                } else if (Constant.account_type_project_consume.equals(accountTradeRecord.getAccountType())) {
                    //设置短信账户 发送 否则不发送
                    if (StringUtils.isNotBlank(baseStore.getSmsAccount())) {
                        try {
                            chuangLanBeanSmsUtil.sendCashByCourseSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
                        } catch (IOException e) {
                            log.error("SsmCashController.doCash:", e);
                        } catch (SmsException e) {
                            log.error("SsmCashController.doCash:", e);
                            genericResponse.setCodeAndMsg(e);
                        }
                    }
                }
            }
        }
        return genericResponse;
    }

    //todo 买单接口
    @ApiOperation(value = "直接收银 (门店端-服务单-直接收银)--升级",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/addCash")
//    @RequestMapping("/addCashNew")
    public GenericResponse addCash(MultipartFile file,@RequestParam String cashListRequestList,HttpSession session) throws IOException, SmsException {
        GenericResponse genericResponse = new GenericResponse<>();
        CashSignatureFile cashSignatureFile = new CashSignatureFile();
        if(SessionHelp.getStoreId(session)==null){
            genericResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return genericResponse;
        }
        if (null != file) {
            String fileName = file.getOriginalFilename();//获取文件名
            String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());//获取文件后缀
            String saveName = DateUtils.getDateNowStr() + "." + suffix;//将文件名用时间重命名
            String path = Constant.filePath + "/" + SessionHelp.getStoreId(session);//文件上传路径

            cashSignatureFile.setFileName(saveName);
            cashSignatureFile.setFilePath(path);
            InputStream inputStream = null;
            boolean b = false;
            try {
                inputStream = file.getInputStream();
                b = new FtpUtils().uploadFile(path, saveName, inputStream);
            } catch (IOException e) {
                log.error("SsmCashController.addCashList:", e);
                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
                return genericResponse;
            }
            if (!b){
                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
                return genericResponse;
            }
        }
//        System.out.println(cashListRequestList);
//        List<CashListRequest> userList  = JSON.parseObject(cashListRequestList, new TypeReference<List<CashListRequest>>(){});
//        System.out.println(cashListRequestList.trim());
        List<CashListRequest> collect = JSON.parseArray(cashListRequestList.trim(),CashListRequest.class);
        List<CashListRequest> cashListRequests = collect.stream().filter(item -> item.getProjectId() != null).collect(Collectors.toList());
        if(cashListRequests!=null && cashListRequests.get(0)!=null && cashListRequests.get(0).getManNumber()==null
                && cashListRequests.get(0).getWomanNumber()==null){//如果男和女都为空的话，默认设置男客单数量为1
            for(CashListRequest cashListRequest:cashListRequests){//设置第一条的男客单数为1,结束
                cashListRequest.setManNumber(new BigDecimal("1"));
                break;
            }
        }

        Long storeId = SessionHelp.getStoreId(session);
        String mobilePhone = cashListRequests.get(0).getMobilePhone();
        if(mobilePhone!=null) {
            String cash = redisClient.get( "cash-" + mobilePhone);

            if (cash != null) {
                genericResponse.setCodeAndMsg(ResponseCode.MSG, "请勿重复提交");
                return genericResponse;
            }
            String uuid = UUID.randomUUID().toString();
            redisClient.set( "cash-" + mobilePhone, uuid, 20L, TimeUnit.SECONDS);
        }
        String storeName = SessionHelp.getStoreName(session);
        String phone = SessionHelp.getLoginAccount(session);
        String num = SessionHelp.getStoreNum(session);
        List<AccountTradeRecord> list = new ArrayList<>();
        if(cashListRequests.size()>0){
            try {
                for(CashListRequest cashListRequest:cashListRequests){
                    if(cashListRequest.getCollectionRechargeAmount().doubleValue()<0){
                        throw new SmsException("010000","操作失败，输入值不能小于0");
                    }
                }
                list = ssmCashService.addCash(cashListRequests,storeId,storeName,phone, cashSignatureFile);//
            }catch (SmsException e){
                genericResponse.setCodeAndMsg(e);
                return genericResponse;
            }catch (Exception e){
                log.error("SsmCashController.addCashList:",e);
                genericResponse.setCodeAndMsg(ResponseCode.FAILED);
                return genericResponse;
            }
        }else{
            genericResponse.setCodeAndMsg(ResponseCode.FAILEDPROJECT);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        if(cashListRequests.get(0).getIsSendSms()==1) {
            if (list.size() > 0) {
                if(list.get(0).getMemberPhone()==null || list.get(0).getMemberPhone().equals("")){
                    genericResponse.setCodeAndMsg(ResponseCode.OK);
                    return genericResponse;
                }
                Boolean is = false;
                BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeId);
                //卡付集合
                List<AccountTradeRecord> value1 = new ArrayList<>();
                //手机号码
                String phone1 = "";
                if (StringUtils.isNotBlank(baseStore.getSmsAccount()) && null != baseStore.getMessagingPlatform()) {
                    try {
                        for (AccountTradeRecord accountTradeRecord : list) {
                            //充值卡支付
                            if (accountTradeRecord.getAccountType().equals(Constant.account_type_recharge_consume)) {
                                if (accountTradeRecord.getIsAddition() != 1) {
                                    phone1 = accountTradeRecord.getMemberPhone();
                                    value1.add(accountTradeRecord);
                                }
                            } else if (accountTradeRecord.getAccountType().equals(Constant.account_type_project_consume)) {//疗程支付
                                if (accountTradeRecord.getIsAddition() != 1) {
//                                    chuangLanBeanSmsUtil.sendCashByCourseSms(baseStore,
//                                            accountTradeRecord.getMemberPhone(),
//                                            accountTradeRecord.getTradeName(),
//                                            accountTradeRecord.getAccountSpendCount(),
//                                            accountTradeRecord.getAccountConsumeCount());
                                    try {
                                        chuangLanBeanSmsUtil.sendCashByCourseSmsNew(baseStore,
                                                accountTradeRecord.getMemberPhone(),
                                                accountTradeRecord.getTradeName(),
                                                accountTradeRecord.getAccountSpendCount(),
                                                accountTradeRecord.getAccountConsumeCount(),accountTradeRecord.getMemberName());
                                    } catch (IOException e) {
                                        log.error("SsmCashController.doCash:", e);
                                    } catch (SmsException e) {
                                        log.error("SsmCashController.doCash:", e);
                                        genericResponse.setCodeAndMsg(e);
                                    }
                                }
                            }
                            //全是现金
                            else {
                                //设置短信账户 发送 否则不发送
                                if (StringUtils.isNotBlank(baseStore.getSmsAccount()) && null != baseStore.getMessagingPlatform()) {
                                    try {
                            chuangLanBeanSmsUtil.sendSLStoreCashProjectPaySmsNew(baseStore, accountTradeRecord.getMemberName(), accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getTradeCount(), accountTradeRecord.getAccountConsumeCount());
//                                        chuangLanBeanSmsUtil.sendCashByCourseSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
                                    } catch (IOException e) {
                                        log.error("SsmCashController.doCash:", e);
                                    } catch (SmsException e) {
                                        log.error("SsmCashController.doCash:", e);
                                        genericResponse.setCodeAndMsg(e);
                                    }
                                }
                            }
                        }
                        if (value1.size() > 0) {
//                            chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1(baseStore, phone1, value1);
//                            chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1New(baseStore, phone1, value1);
                            chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1NewHuiZhong(baseStore, phone1, value1);
                        }

                    } catch (IOException e) {
                        log.error("SsmCashController.addCashList:", e);
                    } catch (SmsException e) {
                        genericResponse.setCodeAndMsg(ResponseCode.SMS_SEND_OK_EXCEPTION);
                        log.error("SsmCashController.addCashList:", e);
                        //genericResponse.setCodeAndMsg(e);
                    }
                } else {
                    genericResponse.setCodeAndMsg(ResponseCode.SMS_NO_OK);
                }
            }
        }else {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    /**
     * 测试短信
     * @param file
     * @param cashListRequestList
     * @param session
     * @return
     * @throws IOException
     * @throws SmsException
     */
    @ApiOperation(value = "直接收银 (门店端-服务单-直接收银)--升级",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/addCashNew")
//    @RequestMapping("/addCash")
    public GenericResponse addCashNew(MultipartFile file,@RequestParam String cashListRequestList,HttpSession session) throws IOException, SmsException {
        GenericResponse genericResponse = new GenericResponse<>();
        CashSignatureFile cashSignatureFile = new CashSignatureFile();
        if(SessionHelp.getStoreId(session)==null){
            genericResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return genericResponse;
        }
        if (null != file) {
            String fileName = file.getOriginalFilename();//获取文件名
            String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());//获取文件后缀
            String saveName = DateUtils.getDateNowStr() + "." + suffix;//将文件名用时间重命名
            String path = Constant.filePath + "/" + SessionHelp.getStoreId(session);//文件上传路径

            cashSignatureFile.setFileName(saveName);
            cashSignatureFile.setFilePath(path);
            InputStream inputStream = null;
            boolean b = false;
            try {
                inputStream = file.getInputStream();
                b = new FtpUtils().uploadFile(path, saveName, inputStream);
            } catch (IOException e) {
                log.error("SsmCashController.addCashList:", e);
                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
                return genericResponse;
            }
            if (!b){
                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
                return genericResponse;
            }
        }
//        System.out.println(cashListRequestList);
//        List<CashListRequest> userList  = JSON.parseObject(cashListRequestList, new TypeReference<List<CashListRequest>>(){});
//        System.out.println(cashListRequestList.trim());
        List<CashListRequest> collect = JSON.parseArray(cashListRequestList.trim(),CashListRequest.class);
        List<CashListRequest> cashListRequests = collect.stream().filter(item -> item.getProjectId() != null).collect(Collectors.toList());
        if(cashListRequests!=null && cashListRequests.get(0)!=null && cashListRequests.get(0).getManNumber()==null
                && cashListRequests.get(0).getWomanNumber()==null){//如果男和女都为空的话，默认设置男客单数量为1
            for(CashListRequest cashListRequest:cashListRequests){//设置第一条的男客单数为1,结束
                cashListRequest.setManNumber(new BigDecimal("1"));
                break;
            }
        }

        Long storeId = SessionHelp.getStoreId(session);
        String mobilePhone = cashListRequests.get(0).getMobilePhone();
        if(mobilePhone!=null) {
            String cash = redisClient.get( "cash-" + mobilePhone);

            if (cash != null) {
                genericResponse.setCodeAndMsg(ResponseCode.MSG, "请勿重复提交");
                return genericResponse;
            }
            String uuid = UUID.randomUUID().toString();
            redisClient.set( "cash-" + mobilePhone, uuid, 20L, TimeUnit.SECONDS);
        }
        String storeName = SessionHelp.getStoreName(session);
        String phone = SessionHelp.getLoginAccount(session);
        String num = SessionHelp.getStoreNum(session);
        List<AccountTradeRecord> list = new ArrayList<>();
        if(cashListRequests.size()>0){
            try {
                for(CashListRequest cashListRequest:cashListRequests){
                    if(cashListRequest.getCollectionRechargeAmount().doubleValue()<0){
                        throw new SmsException("010000","操作失败，输入值不能小于0");
                    }
                }
                list = ssmCashService.addCash(cashListRequests,storeId,storeName,phone, cashSignatureFile);//
            }catch (SmsException e){
                genericResponse.setCodeAndMsg(e);
                return genericResponse;
            }catch (Exception e){
                log.error("SsmCashController.addCashList:",e);
                genericResponse.setCodeAndMsg(ResponseCode.FAILED);
                return genericResponse;
            }
        }else{
            genericResponse.setCodeAndMsg(ResponseCode.FAILEDPROJECT);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        if(cashListRequests.get(0).getIsSendSms()==1) {

            if (list.size() > 0) {
                Boolean is = false;
                BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeId);
                SmsFix smsFix = new SmsFix();
                if(baseStore.getParentId()==null){
                    smsFix.setStoreId(baseStore.getId());
                }
                else smsFix.setStoreId(baseStore.getParentId());

                List<Integer> types = new ArrayList<>();
                types.add(3);
                types.add(4);
                types.add(5);
                smsFix.setTypes(types);

                List<SmsFix> smsFixList = smsFixService.selectByTypeAndStoreId(smsFix);
                SmsFix smsFixCash = null;
                SmsFix smsFixRecharge =null;
                SmsFix smsFixCourse=null;
                for (SmsFix fix : smsFixList) {
                    if(fix.getType()==3){
                        smsFixCash = fix;
                    }
                    if(fix.getType()==4){
                        smsFixRecharge = fix;
                    }
                    if(fix.getType()==5){
                        smsFixCourse = fix;
                    }
                }
                //卡付集合
                List<AccountTradeRecord> value1 = new ArrayList<>();
                //手机号码
                String phone1 = "";
                if (StringUtils.isNotBlank(baseStore.getSmsAccount()) && null != baseStore.getMessagingPlatform()) {
                    try {
                        for (AccountTradeRecord accountTradeRecord : list) {
                            //充值卡支付
                            if (accountTradeRecord.getAccountType().equals(Constant.account_type_recharge_consume)) {
                                if (accountTradeRecord.getIsAddition() != 1) {
                                    phone1 = accountTradeRecord.getMemberPhone();
                                    value1.add(accountTradeRecord);
                                }
                            } else if (accountTradeRecord.getAccountType().equals(Constant.account_type_project_consume)) {//疗程支付

                                if (accountTradeRecord.getIsAddition() != 1) {
//                                    chuangLanBeanSmsUtil.sendCashByCourseSms(baseStore,
//                                            accountTradeRecord.getMemberPhone(),
//                                            accountTradeRecord.getTradeName(),
//                                            accountTradeRecord.getAccountSpendCount(),
//                                            accountTradeRecord.getAccountConsumeCount());
                                    if(smsFixCourse==null){
                                        genericResponse.setCodeAndMsg(ResponseCode.MSG,"收银疗程付未配置短信模板!");
                                        return genericResponse;
                                    }
                                    try {
                                        //修改后的疗程收银卡付短信
                                        chuangLanBeanSmsUtil.sendCashByCourseSmsNewBySmsFix(baseStore,
                                                accountTradeRecord,smsFixCourse);
                                    } catch (IOException e) {
                                        log.error("SsmCashController.doCash:", e);
                                    } catch (SmsException e) {
                                        log.error("短信发送失败SsmCashController.doCash:", e);
                                        genericResponse.setCodeAndMsg(e);
                                    }
                                }
                            }
                            //全是现金
                            else {
                                //设置短信账户 发送 否则不发送
                                if (StringUtils.isNotBlank(baseStore.getSmsAccount()) && null != baseStore.getMessagingPlatform()) {
                                    try {
                                        if(smsFixCash==null){
                                            genericResponse.setCodeAndMsg(ResponseCode.MSG,"现金收银未配置短信模板!");
                                            return genericResponse;
                                        }
//                                        chuangLanBeanSmsUtil.sendSLStoreCashProjectPaySmsNew(baseStore, accountTradeRecord.getMemberName(), accountTradeRecord.getMemberPhone(),
//                                                accountTradeRecord.getTradeName(), accountTradeRecord.getTradeCount(), accountTradeRecord.getAccountConsumeCount());
                                        chuangLanBeanSmsUtil.sendSLStoreCashProjectPaySmsNewBySmsFix(baseStore, accountTradeRecord,smsFixCash);
//                                        chuangLanBeanSmsUtil.sendCashByCourseSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
                                    } catch (IOException e) {
                                        log.error("SsmCashController.doCash:", e);
                                    } catch (SmsException e) {
                                        log.error("短信发送失败SsmCashController.doCash:", e);
                                        genericResponse.setCodeAndMsg(e);
                                    }
                                }
                            }
                        }
                        if (value1.size() > 0) {
                            if(smsFixRecharge==null){
                                genericResponse.setCodeAndMsg(ResponseCode.MSG,"收银充值卡付未配置短信模板!");
                                return genericResponse;
                            }
//                            chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1(baseStore, phone1, value1);
//                            chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1New(baseStore, phone1, value1);
                            chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1NewBySmsFix(baseStore, phone1, value1,smsFixRecharge);
                        }

                    } catch (IOException e) {
                        log.error("SsmCashController.addCashList:", e);
                    } catch (SmsException e) {
                        genericResponse.setCodeAndMsg(ResponseCode.SMS_SEND_OK_EXCEPTION);
                        log.error("短信发送失败SsmCashController.addCashList:", e);
                        //genericResponse.setCodeAndMsg(e);
                    }
                } else {
                    genericResponse.setCodeAndMsg(ResponseCode.SMS_NO_OK);
                }
            }
        }else {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }



    @ApiOperation(value = "直接收银补单短信重发",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/retransmission")
//    @RequestMapping("/retransmissionNew")
    public GenericResponse retransmission(@RequestBody CashListResponse cashListResponse, HttpSession session){
        Date additionDate=new Date();
        GenericResponse genericResponse = new GenericResponse<>();
        AccountTradeRecord accountTradeRecord=new AccountTradeRecord();
        Long storeId = SessionHelp.getStoreId(session);
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeId);
        //卡付集合
        List<AccountTradeRecord> value1 = new ArrayList<>();
        //手机号码
        String phone1 = "";
        for(ProjectRequest a:cashListResponse.getProjectList()){
            accountTradeRecord.setDocId(a.getCashId());
            accountTradeRecord.setInputDate(a.getCashDate());
            try {
                accountTradeRecord = ssmCashService.retransmission(accountTradeRecord);
            }catch (SmsException e){
                genericResponse.setCodeAndMsg(e);
                return genericResponse;
            }catch (Exception e){
                log.error("SsmCashController.retransmission:",e);
                genericResponse.setCodeAndMsg(ResponseCode.FAILED);
                return genericResponse;
            }


        if (accountTradeRecord!=null) {
                try {
                    //充值卡支付
                    if (accountTradeRecord.getAccountType().equals(Constant.account_type_recharge_consume)) {
                        if (accountTradeRecord.getIsAddition() != 1) {
                            phone1 = accountTradeRecord.getMemberPhone();
                            value1.add(accountTradeRecord);
                        }
                    } else if(accountTradeRecord.getAccountType().equals(Constant.account_type_project_consume )){
                            int sum = accountTradeRecord.getAccountSpendCount();
                            chuangLanBeanSmsUtil.sendCashByCourseSmsNew(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), sum, accountTradeRecord.getAccountConsumeCount(),accountTradeRecord.getMemberName());
                    }else {
                        //设置短信账户 发送 否则不发送
                        if (StringUtils.isNotBlank(baseStore.getSmsAccount()) && null != baseStore.getMessagingPlatform()) {
                            try {
                                chuangLanBeanSmsUtil.sendSLStoreCashProjectPaySmsNew(baseStore, accountTradeRecord.getMemberName(), accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getTradeCount(), accountTradeRecord.getAccountConsumeCount());
//                                        chuangLanBeanSmsUtil.sendCashByCourseSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
                            } catch (IOException e) {
                                log.error("SsmCashController.doCash:", e);
                            } catch (SmsException e) {
                                log.error("SsmCashController.doCash:", e);
                                genericResponse.setCodeAndMsg(e);
                            }
                        }
                    }
                    genericResponse.setCodeAndMsg(ResponseCode.OK);
                } catch (IOException e) {
                    log.error("SsmCashController.addCashList:", e);
                } catch (SmsException e) {
                    log.error("SsmCashController.addCashList:", e);
                    genericResponse.setCodeAndMsg(e);
                }
        }
        }
        if (value1.size() > 0) {
//                            chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1(baseStore, phone1, value1);
            try {
//                chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1New(baseStore, phone1, value1);
                chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1NewHuiZhong(baseStore, phone1, value1);

            } catch (IOException e) {
                log.error("SsmCashController.addCashList:", e);
            } catch (SmsException e) {
                log.error("SsmCashController.addCashList:", e);
                genericResponse.setCodeAndMsg(e);
            }
        }
        return genericResponse;
    }

    @ApiOperation(value = "直接收银补单短信重发",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/retransmissionNew")
//    @RequestMapping("/retransmission")
    public GenericResponse retransmissionNew(@RequestBody CashListResponse cashListResponse, HttpSession session){
        Date additionDate=new Date();
        GenericResponse genericResponse = new GenericResponse<>();
        AccountTradeRecord accountTradeRecord=new AccountTradeRecord();
        Long storeId = SessionHelp.getStoreId(session);
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeId);
        //卡付集合
        List<AccountTradeRecord> value1 = new ArrayList<>();
        //手机号码
        String phone1 = "";
        SmsFix smsFix = new SmsFix();
        if(baseStore.getParentId()==null){
            smsFix.setStoreId(baseStore.getId());
        }
        else smsFix.setStoreId(baseStore.getParentId());

        List<Integer> types = new ArrayList<>();
        types.add(3);
        types.add(4);
        types.add(5);
        smsFix.setTypes(types);

        List<SmsFix> smsFixList = smsFixService.selectByTypeAndStoreId(smsFix);
        SmsFix smsFixCash = null;
        SmsFix smsFixRecharge =null;
        SmsFix smsFixCourse=null;
        for (SmsFix fix : smsFixList) {
            if(fix.getType()==3){
                smsFixCash = fix;
            }
            if(fix.getType()==4){
                smsFixRecharge = fix;
            }
            if(fix.getType()==5){
                smsFixCourse = fix;
            }
        }
        for(ProjectRequest a:cashListResponse.getProjectList()){
            accountTradeRecord.setDocId(a.getCashId());

            try {
                accountTradeRecord = ssmCashService.retransmission(accountTradeRecord);
            }catch (SmsException e){
                genericResponse.setCodeAndMsg(e);
                return genericResponse;
            }catch (Exception e){
                log.error("SsmCashController.retransmission:",e);
                genericResponse.setCodeAndMsg(ResponseCode.FAILED);
                return genericResponse;
            }


            if (accountTradeRecord!=null) {

                try {
                    //充值卡支付
                    if (accountTradeRecord.getAccountType().equals(Constant.account_type_recharge_consume)) {
                        if (accountTradeRecord.getIsAddition() != 1) {
                            phone1 = accountTradeRecord.getMemberPhone();
                            value1.add(accountTradeRecord);
                        }
                    } else if(accountTradeRecord.getAccountType().equals(Constant.account_type_project_consume )){
                        if(smsFixCourse==null){
                            genericResponse.setCodeAndMsg(ResponseCode.MSG,"收银疗程付未配置短信模板!");
                            return genericResponse;
                        }
                        int sum = accountTradeRecord.getAccountSpendCount();
                        chuangLanBeanSmsUtil.sendCashByCourseSmsNewBySmsFix(baseStore,
                                accountTradeRecord,smsFixCourse);
//                        chuangLanBeanSmsUtil.sendCashByCourseSmsNew(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), sum, accountTradeRecord.getAccountConsumeCount(),accountTradeRecord.getMemberName());
                    }else {
                        //设置短信账户 发送 否则不发送
                        if (StringUtils.isNotBlank(baseStore.getSmsAccount()) && null != baseStore.getMessagingPlatform()) {
                            try {
                                if(smsFixCash==null){
                                    genericResponse.setCodeAndMsg(ResponseCode.MSG,"现金收银未配置短信模板!");
                                    return genericResponse;
                                }
                                chuangLanBeanSmsUtil.sendSLStoreCashProjectPaySmsNewBySmsFix(baseStore, accountTradeRecord,smsFixCash);
//                                chuangLanBeanSmsUtil.sendSLStoreCashProjectPaySmsNew(baseStore, accountTradeRecord.getMemberName(), accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getTradeCount(), accountTradeRecord.getAccountConsumeCount());
//                                        chuangLanBeanSmsUtil.sendCashByCourseSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
                            } catch (IOException e) {
                                log.error("SsmCashController.doCash:", e);
                            } catch (SmsException e) {
                                log.error("SsmCashController.doCash:", e);
                                genericResponse.setCodeAndMsg(e);
                            }
                        }
                    }
                    genericResponse.setCodeAndMsg(ResponseCode.OK);
                } catch (IOException e) {
                    log.error("SsmCashController.addCashList:", e);
                } catch (SmsException e) {
                    log.error("SsmCashController.addCashList:", e);
                    genericResponse.setCodeAndMsg(e);
                }
            }
        }
        if (value1.size() > 0) {
            if(smsFixRecharge==null){
                genericResponse.setCodeAndMsg(ResponseCode.MSG,"收银充值卡付未配置短信模板!");
                return genericResponse;
            }
//                            chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1(baseStore, phone1, value1);
            try {
//                chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1New(baseStore, phone1, value1);
                chuangLanBeanSmsUtil.sendCashByRechargeSmsSL1NewBySmsFix(baseStore, phone1, value1,smsFixRecharge);
            } catch (IOException e) {
                log.error("SsmCashController.addCashList:", e);
            } catch (SmsException e) {
                log.error("SsmCashController.addCashList:", e);
                genericResponse.setCodeAndMsg(e);
            }
        }
        return genericResponse;
    }
    // TODO 收银短信发送放入rabbitmq中
//    @ApiOperation(value = "直接收银 (门店端-服务单-直接收银)",httpMethod = "POST",response = GenericResponse.class)
//    @RequestMapping("/addCashList")
//    public GenericResponse addCashList(MultipartFile file,@RequestParam String cashListRequestList,HttpSession session){
//        GenericResponse genericResponse = new GenericResponse<>();
//        CashSignatureFile cashSignatureFile = new CashSignatureFile();
//        if (null != file) {
//            String fileName = file.getOriginalFilename();//获取文件名
//            String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());//获取文件后缀
//            String saveName = DateUtils.getDateNowStr() + "." + suffix;//将文件名用时间重命名
//            String path = Constant.filePath + "/" + SessionHelp.getStoreId(session);//文件上传路径
//
//            cashSignatureFile.setFileName(saveName);
//            cashSignatureFile.setFilePath(path);
//            InputStream inputStream = null;
//            boolean b = false;
//            try {
//                inputStream = file.getInputStream();
//                b = new FtpUtils().uploadFile(path, saveName, inputStream);
//            } catch (IOException e) {
//                log.error("SsmCashController.addCashList:", e);
//                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
//                return genericResponse;
//            }
//            if (!b){
//                genericResponse.setCodeAndMsg(ResponseCode.FILE_UPLOAD_FAILED);
//                return genericResponse;
//            }
//        }
//
//        List<CashListRequest> cashListRequests = JSON.parseArray(cashListRequestList,CashListRequest.class);
//        Long storeId = SessionHelp.getStoreId(session);
//        String storeName = SessionHelp.getStoreName(session);
//        String phone = SessionHelp.getLoginAccount(session);
//        List<AccountTradeRecord> list = new ArrayList<>();
//
//        try {
//            list = ssmCashService.addCashList(cashListRequests,storeId,storeName,phone, cashSignatureFile);
//        }catch (SmsException e){
//            genericResponse.setCodeAndMsg(e);
//            return genericResponse;
//        }catch (Exception e){
//            log.error("SsmCashController.addCashList:",e);
//            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
//            return genericResponse;
//        }
//
//        genericResponse.setCodeAndMsg(ResponseCode.OK);
//
//        if (list.size() > 0) {
//            BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeId);
//            for (AccountTradeRecord accountTradeRecord : list) {
//                Map map = new HashMap();
////                map.put("memberPhone",accountTradeRecord.getMemberPhone());
////                map.put("spendMoney", accountTradeRecord.getAccountSpendMoney());
////                map.put("consumeMoney", accountTradeRecord.getAccountConsumeMoney());
////                map.put("projectName", accountTradeRecord.getTradeName());
////                map.put("spendCount", accountTradeRecord.getAccountSpendCount());
////                map.put("consumeCount", accountTradeRecord.getAccountConsumeCount());
//                map.put("accountTradeRecord", accountTradeRecord);
//                map.put("baseStore",baseStore);
//                rabbitTemplate.convertAndSend(CASH_TOPIC_EXCHANGE, CASH_ROUKEY, JSON.toJSONString(map));
//            }
//        }
//        return genericResponse;
//    }

    @ApiOperation(value = "会员查询消费记录 (会员小程序-会员查询消费记录)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/selectByMember")
    public PageResponse selectByMember(@RequestBody CashListRequest cashListRequest,HttpSession session){
        PageResponse<CashListResponse> pageResponse = new PageResponse<>();
        PageInfo<CashListResponse> pageInfo = new PageInfo<>();
        Long storeId = SessionHelp.getStoreId(session);
        if(SessionHelp.getStoreId(session)==null){
            pageResponse.setCodeAndMsg(ResponseCode.MSG,"登录失效，请退出重新登录！");
            return pageResponse;
        }
        cashListRequest.setStoreId(storeId);

        try {
            pageInfo = ssmCashService.selectByMember(cashListRequest);
        }catch (SmsException e){
            pageResponse.setCodeAndMsg(e);
            return pageResponse;
        }catch (Exception e){
            log.error("SsmCashController.selectByMember:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }

        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @ApiOperation(value = "签名文件查询 (门店收银-签名文件查询)",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/signature")
    public GenericResponse signature(@RequestBody CashSignatureFile cashSignatureFile){
        GenericResponse<CashSignatureFile> genericResponse = new GenericResponse<>();
        List<CashSignatureFile> list = new ArrayList<>();
        try {
            list = ssmCashSignatureService.select(cashSignatureFile);
//            for (CashSignatureFile file : list) {
//                CashListRequest cashList = new CashListRequest();
//                String docNum = file.getCashNum();
//                cashList.setCashNum(docNum);
//                String substring = docNum.substring(docNum.length()-11, docNum.length() - 3);
////                System.out.println(substring);
//                StrBuilder strBuilder = new StrBuilder(substring);
//                StrBuilder insert = strBuilder.insert(6, "-").insert(4, "-");
//                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//                Date parse = simpleDateFormat.parse(String.valueOf(insert));
//                cashList.setCashDate(parse);
////                System.out.println(insert);
//                List<CashList> cashLists = ssmCashService.selectList(cashList);
//                for (CashList cashList1 : cashLists) {
//                    if(cashList1.getCourseAccountId()!=null){
//                        CourseAccount courseAccount = new CourseAccount();
//                        courseAccount.setId(cashList1.getCourseAccountId());
//                        CourseAccount courseAccount1 = ssmCourseAccountService.selectOne(courseAccount);
//                        file.setCourseRestCount(courseAccount1.getCourseRestCount());
//                    }
//                }
//            }
        }catch (Exception e){
            log.error("SsmCashController.signature:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }

        genericResponse.setCodeAndMsg(ResponseCode.OK);
        if (list.size() > 0) {
            genericResponse.setData(list.get(0));
        }
        return genericResponse;
    }
    @ApiOperation(value = "单据导出", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/cashList/exportachis")
    public void exportachis(@RequestBody CashListRequest cashListRequest) {
        // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
        // {} 代表普通变量 {.} 代表是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/cashList.xlsx");
//            BeanUtils.copyProperties(projectTypeRequest, baseProjectType);
            List<ExcelCashListNew> excelBaseProjectTypeList = new ArrayList<>();
            List<CashList> list = ssmCashService.selectListByMonthly(cashListRequest);
            AccountTradeRecordRequest accountTradeRecordRequest = new AccountTradeRecordRequest();
            accountTradeRecordRequest.setInputDate(cashListRequest.getCashDate());
            accountTradeRecordRequest.setStoreIds(cashListRequest.getStoreIds());
            accountTradeRecordRequest.setDocType("store_cash");
            List<AccountTradeRecord> accountTradeRecordList = ssmAccountTradeRecordService.selectListByMonthly(accountTradeRecordRequest);
            //查询充值账户
            List<Long> collect1 = accountTradeRecordList.stream().map(item -> item.getAccountId()).collect(Collectors.toList());
            List<RechargeAccount>  rechargeAccountList = ssmRechargeAccountService.selectAll();
//            List<RechargeAccount>  rechargeAccountList = ssmRechargeAccountService.selectByIds(collect1);

            if(list!=null && list.size()>0) {
//            salesmen = ssmSalesmanService.selectList(salesman);
                //所有门店
                List<BaseStore> select = ssmBaseStoreService.select(null);
                //所有项目id
                List<Long> projectIds = list.stream().filter(cashList -> cashList.getProjectId() != null).map(CashList::getProjectId).collect(Collectors.toList());
                List<BaseProject> projectList = ssmProjectService.selectList(projectIds);
                //所有单据号
                List<String> courseNums = list.stream().map(CashList::getCashNum).collect(Collectors.toList());
                List<PayList> payListList = ssmPayService.selectList(courseNums);
                //查询管理层和高管
                List<Long> courseIds = list.stream().map(CashList::getId).collect(Collectors.toList());
                List<Salesman> salesmanList = ssmSalesmanService.selectList(courseIds);
                for (CashList executives : list) {
                    ExcelCashListNew excelBaseProjectType = new ExcelCashListNew();
                    BeanUtils.copyProperties(executives, excelBaseProjectType);
                    //设置充值卡支付的账号和金额
                    List<AccountTradeRecord> collect = accountTradeRecordList.stream().filter(item ->
                            (item.getDocId() == executives.getId() || item.getDocId().toString().equals(executives.getId().toString()))
                                    && (item.getOrderStatu() == null || item.getOrderStatu()==0)&&item.getAccountType().equals("recharge_consume")).collect(Collectors.toList());
                    StringBuffer rechargePay = new StringBuffer("");

                    if(collect!=null && collect.size()>0){
                        for (AccountTradeRecord accountTradeRecord : collect) {
                            for (RechargeAccount rechargeAccount : rechargeAccountList) {
                                if(accountTradeRecord.getAccountId()==rechargeAccount.getId() || accountTradeRecord.getAccountId().toString().equals(rechargeAccount.getId().toString())){
                                    rechargePay = rechargePay.append(rechargeAccount.getRechargeTypeNum() +"-"+ accountTradeRecord.getAccountName()+"-通用金额支付："
                                            +accountTradeRecord.getAccountSpendMoney()+"元-赠送金额支付："+accountTradeRecord.getAccountGiftSpendMoney()+"元\r\n");
                                }
                            }
                        }
                    }
                    excelBaseProjectType.setRechargePay(rechargePay.toString());
                    excelBaseProjectType.setPayType("");
                    if (excelBaseProjectType.getIsCancel() == 0) {
                        excelBaseProjectType.setIsCancelNew("正常");
                    } else if (excelBaseProjectType.getIsCancel() == 1) {
                        excelBaseProjectType.setIsCancelNew("作废");
                    }
                    if (excelBaseProjectType.getCashNumber() == 1) {
                        excelBaseProjectType.setIsMember("是");
                    }else {
                        excelBaseProjectType.setIsMember("否");
                    }
                    //设置项目编码
                    if (executives.getProjectId() != null) {
                        for (BaseProject baseProject : projectList) {
                            if (executives.getProjectId() == baseProject.getId() || executives.getProjectId().equals(baseProject.getId())) {
                                executives.setProjectNum(baseProject.getProjectNum());
                            }
                        }
                    }
                    //设置门店编码
                    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.getCashNum())) {
                            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 hundred = new BigDecimal("100");
                    //美容师所有业绩
                    BigDecimal largeAchievementAmount = excelBaseProjectType.getLargeAchievementAmount().add(excelBaseProjectType.getCardLargeAchievementAmount());
                    //美容师所有提成
                    BigDecimal largeCommissionAmount = excelBaseProjectType.getLargeCommissionAmount().add(excelBaseProjectType.getCardLargeCommissionAmount());
                    //美发师所有业绩
                    BigDecimal zhonggongAchievementAmount = excelBaseProjectType.getZhonggongAchievementAmount().add(excelBaseProjectType.getCardZhonggongAchievementAmount());
                    //美发师所有提成
                    BigDecimal zhonggongCommissionAmount = excelBaseProjectType.getZhonggongCommissionAmount().add(excelBaseProjectType.getCardZhonggongCommissionAmount());
                    //技师所有业绩
                    BigDecimal technicianAchievementAmount = excelBaseProjectType.getTechnicianAchievementAmount().add(excelBaseProjectType.getCardTechnicianAchievementAmount());
                    //技师所有提成
                    BigDecimal technicianCommissionAmount = excelBaseProjectType.getTechnicianCommissionAmount().add(excelBaseProjectType.getCardTechnicianCommissionAmount());
                    //助理所有业绩
                    BigDecimal smallAchievementAmount = excelBaseProjectType.getSmallAchievementAmount().add(excelBaseProjectType.getCardSmallAchievementAmount());
                    //助理所有提成
                    BigDecimal smallCommissionAmount = excelBaseProjectType.getSmallCommissionAmount().add(excelBaseProjectType.getCardSmallCommissionAmount());

                    //美容师
                    if (excelBaseProjectType.getServiceLargeOneStaffId() != null) {
                        excelBaseProjectType.setServiceLargeOneAchievementAmount(largeAchievementAmount.multiply(excelBaseProjectType.getServiceLargeOneRatio().divide(hundred)));
                        excelBaseProjectType.setServiceLargeOneCommissionAmount(largeCommissionAmount.multiply(excelBaseProjectType.getServiceLargeOneRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceLargeTwoStaffId() != null) {
                        excelBaseProjectType.setServiceLargeTwoAchievementAmount(largeAchievementAmount.multiply(excelBaseProjectType.getServiceLargeTwoRatio().divide(hundred)));
                        excelBaseProjectType.setServiceLargeTwoCommissionAmount(largeCommissionAmount.multiply(excelBaseProjectType.getServiceLargeTwoRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceLargeThreeStaffId() != null) {
                        excelBaseProjectType.setServiceLargeThreeAchievementAmount(largeAchievementAmount.multiply(excelBaseProjectType.getServiceLargeThreeRatio().divide(hundred)));
                        excelBaseProjectType.setServiceLargeThreeCommissionAmount(largeCommissionAmount.multiply(excelBaseProjectType.getServiceLargeThreeRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceLargeFourStaffId() != null) {
                        excelBaseProjectType.setServiceLargeFourAchievementAmount(largeAchievementAmount.multiply(excelBaseProjectType.getServiceLargeFourRatio().divide(hundred)));
                        excelBaseProjectType.setServiceLargeFourCommissionAmount(largeCommissionAmount.multiply(excelBaseProjectType.getServiceLargeFourRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceLargeFiveStaffId() != null) {
                        excelBaseProjectType.setServiceLargeFiveAchievementAmount(largeAchievementAmount.multiply(excelBaseProjectType.getServiceLargeFiveRatio().divide(hundred)));
                        excelBaseProjectType.setServiceLargeFiveCommissionAmount(largeCommissionAmount.multiply(excelBaseProjectType.getServiceLargeFiveRatio().divide(hundred)));
                    }

                    //美发师
                    if (excelBaseProjectType.getServiceZhonggongOneStaffId() != null) {
                        excelBaseProjectType.setServiceZhonggongOneAchievementAmount(zhonggongAchievementAmount.multiply(excelBaseProjectType.getServiceZhonggongOneRatio().divide(hundred)));
                        excelBaseProjectType.setServiceZhonggongOneCommissionAmount(zhonggongCommissionAmount.multiply(excelBaseProjectType.getServiceZhonggongOneRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceZhonggongTwoStaffId() != null) {
                        excelBaseProjectType.setServiceZhonggongTwoAchievementAmount(zhonggongAchievementAmount.multiply(excelBaseProjectType.getServiceZhonggongTwoRatio().divide(hundred)));
                        excelBaseProjectType.setServiceZhonggongTwoCommissionAmount(zhonggongCommissionAmount.multiply(excelBaseProjectType.getServiceZhonggongTwoRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceZhonggongThreeStaffId() != null) {
                        excelBaseProjectType.setServiceZhonggongThreeAchievementAmount(zhonggongAchievementAmount.multiply(excelBaseProjectType.getServiceZhonggongThreeRatio().divide(hundred)));
                        excelBaseProjectType.setServiceZhonggongThreeCommissionAmount(zhonggongCommissionAmount.multiply(excelBaseProjectType.getServiceZhonggongThreeRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceZhonggongFourStaffId() != null) {
                        excelBaseProjectType.setServiceZhonggongFourAchievementAmount(zhonggongAchievementAmount.multiply(excelBaseProjectType.getServiceZhonggongFourRatio().divide(hundred)));
                        excelBaseProjectType.setServiceZhonggongFourCommissionAmount(zhonggongCommissionAmount.multiply(excelBaseProjectType.getServiceZhonggongFourRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceZhonggongFiveStaffId() != null) {
                        excelBaseProjectType.setServiceZhonggongFiveAchievementAmount(zhonggongAchievementAmount.multiply(excelBaseProjectType.getServiceZhonggongFiveRatio().divide(hundred)));
                        excelBaseProjectType.setServiceZhonggongFiveCommissionAmount(zhonggongCommissionAmount.multiply(excelBaseProjectType.getServiceZhonggongFiveRatio().divide(hundred)));
                    }
                    //技师
                    if (excelBaseProjectType.getServiceTechnicianOneStaffId() != null) {
                        excelBaseProjectType.setServiceTechnicianOneAchievementAmount(technicianAchievementAmount.multiply(excelBaseProjectType.getServiceTechnicianOneRatio().divide(hundred)));
                        excelBaseProjectType.setServiceTechnicianOneCommissionAmount(technicianCommissionAmount.multiply(excelBaseProjectType.getServiceTechnicianOneRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceTechnicianTwoStaffId() != null) {
                        excelBaseProjectType.setServiceTechnicianTwoAchievementAmount(technicianAchievementAmount.multiply(excelBaseProjectType.getServiceTechnicianTwoRatio().divide(hundred)));
                        excelBaseProjectType.setServiceTechnicianTwoCommissionAmount(technicianCommissionAmount.multiply(excelBaseProjectType.getServiceTechnicianTwoRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceTechnicianThreeStaffId() != null) {
                        excelBaseProjectType.setServiceTechnicianThreeAchievementAmount(technicianAchievementAmount.multiply(excelBaseProjectType.getServiceTechnicianThreeRatio().divide(hundred)));
                        excelBaseProjectType.setServiceTechnicianThreeCommissionAmount(technicianAchievementAmount.multiply(excelBaseProjectType.getServiceTechnicianThreeRatio().divide(hundred)));
                    }
                    //助理
                    if (excelBaseProjectType.getServiceSmallOneStaffId() != null) {
                        excelBaseProjectType.setServiceSmallOneAchievementAmount(smallAchievementAmount.multiply(excelBaseProjectType.getServiceSmallOneRatio().divide(hundred)));
                        excelBaseProjectType.setServiceSmallOneCommissionAmount(smallCommissionAmount.multiply(excelBaseProjectType.getServiceSmallOneRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceSmallTwoStaffId() != null) {
                        excelBaseProjectType.setServiceSmallTwoAchievementAmount(smallAchievementAmount.multiply(excelBaseProjectType.getServiceSmallTwoRatio().divide(hundred)));
                        excelBaseProjectType.setServiceSmallTwoCommissionAmount(smallCommissionAmount.multiply(excelBaseProjectType.getServiceSmallTwoRatio().divide(hundred)));
                    }
                    if (excelBaseProjectType.getServiceSmallThreeStaffId() != null) {
                        excelBaseProjectType.setServiceSmallThreeAchievementAmount(smallAchievementAmount.multiply(excelBaseProjectType.getServiceSmallThreeRatio().divide(hundred)));
                        excelBaseProjectType.setServiceSmallThreeCommissionAmount(smallCommissionAmount.multiply(excelBaseProjectType.getServiceSmallThreeRatio().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();
        }
    }


}
