package com.ssm.manage.service.impl;

import cn.hutool.core.text.StrBuilder;
import com.github.pagehelper.PageInfo;
import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.core.utils.BigDecimalUtils;
import com.ssm.core.utils.SnowflakeUtil;
import com.ssm.core.utils.StoreParaUtils;
import com.ssm.manage.dao.SsmCardChangeDao;
import com.ssm.manage.dao.SsmCourseDao;
import com.ssm.manage.entity.*;
import com.ssm.manage.extendEntity.AchiCommEntity;
import com.ssm.manage.extendEntity.StoreDaily;
import com.ssm.manage.mapper.CardChangeListMapper;
import com.ssm.manage.query.*;
import com.ssm.manage.response.*;
import com.ssm.manage.service.*;
import com.ssm.manage.utils.Constant;
import com.ssm.manage.utils.DateUtils;
import com.ssm.util.RedisClient;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.ssm.manage.utils.Constant.staffKey;

@Service
@Slf4j
public class SsmCardChangeServiceImpl extends BaseServiceImpl<CardChangeList> implements SsmCardChangeService {
    @Autowired
    private RedisClient<StaffResponse> redisClient;

    @Autowired
    private SsmRepayAccountListService ssmRepayAccountListService;

    @Autowired
    private SsmCollectionTypeService ssmCollectionTypeService;

    @Autowired
    private SsmDocPromotionService ssmDocPromotionService;
    @Autowired
    private SsmDocPromotionProjectService ssmDocPromotionProjectService;

    @Autowired
    private SsmCourseService ssmCourseService;

    @Autowired
    private SsmCourseDao ssmCourseDao;

    @Autowired
    private SsmRepayTradeService ssmRepayTradeService;
    @Autowired
    private SsmStoreParaService ssmStoreParaService;

    @Autowired
    private SsmRepayService ssmRepayService;

    @Autowired
    private SsmCancelDebtListService ssmCancelDebtListService;

    @Autowired
    private SsmCardChangeInProjectService ssmCardChangeInProjectService;

    @Autowired
    private SsmProjectService ssmProjectService;

    @Autowired
    private SsmCardChangeOutProjectService ssmCardChangeOutProjectService;

    @Autowired
    private SsmMemberCsService ssmMemberCsService;

    @Autowired
    private SsmDebtService ssmDebtService;

    @Autowired
    private SsmSalesmanService ssmSalesmanService;


    @Autowired
    private SsmPayService ssmPayService;

    @Autowired
    private SsmCourseAccountService ssmCourseAccountService;


    @Autowired
    private SsmCardChangeDao dao;

    @Autowired
    private SsmBaseStoreService ssmBaseStoreService;

    @Override
    public SsmCardChangeDao getDao() {
        return dao;
    }

    @Override
    public PageInfo<CardChangeList> selectPage(CardChangeListRequest cardChangeListRequest) {
        return dao.selectPage(cardChangeListRequest);
    }

    @Override
    public PageInfo<CardChangeList> selectPageNew(CardChangeListRequest cardChangeListRequest) {
        return dao.selectPageNew(cardChangeListRequest);
    }

    @Override
    public PageInfo<CardChangeList> pageDetail(CardChangeListRequest cardChangeListRequest) {
        return dao.pageDetail(cardChangeListRequest);
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public int add(CardChangeListRequest cardChangeListRequest) throws SmsException {
        int i = 0;
        CardChangeList cardChangeList = new CardChangeList();
        BeanUtils.copyProperties(cardChangeListRequest, cardChangeList);
        StoreParament storeParament11 = new StoreParament();
        storeParament11.setStoreId(cardChangeListRequest.getStoreId());
        storeParament11.setParamentName("balance");
        storeParament11 = ssmStoreParaService.selectOne(storeParament11);
        //容差，五毛钱
        BigDecimal balance = new BigDecimal(storeParament11.getParamentValue());
        if (cardChangeList.getDebtMoney()!=null && cardChangeList.getIsDebt()==0){
            throw new SmsException(ResponseCode.MSG, "欠款字段传参错误！");
        }
        //判断支付金额是否和成交金额相等 支付金额+转出金额+欠款金额
        StoreParament storeParament = StoreParaUtils.getStorePara(cardChangeListRequest.getStoreId(), Constant.cardCangeListDebt);
        if("0".equals(storeParament.getParamentValue())){
            BigDecimal amount = BigDecimalUtils.add(BigDecimalUtils.add(cardChangeList.getChangeInPayMoney(), cardChangeList.getChangeOutMoney()), cardChangeList.getDebtMoney());
            if (BigDecimalUtils.compareTo(amount, cardChangeList.getChangeInMoney()) != 0) {
                if(amount.subtract(cardChangeList.getChangeInMoney()).abs().compareTo(balance)==1){
                    throw new SmsException(ResponseCode.MSG, "总金额和成交金额不相等");
                }
            }
        }else{
            BigDecimal out = BigDecimalUtils.bigDecimal("0");
            BigDecimal in = cardChangeListRequest.getCardChangeInProjectRequest().getChangeInMoney()==null?BigDecimal.valueOf(0):cardChangeListRequest.getCardChangeInProjectRequest().getChangeInMoney();
            BigDecimal ray =  BigDecimalUtils.bigDecimal("0");

            List<CardChangeOutProjectRequest> cardChangeOutProjectRequests = cardChangeListRequest.getCardChangeOutProjectRequests();
            for (CardChangeOutProjectRequest cardChangeOutProjectRequest : cardChangeOutProjectRequests) {
                out=out.add(cardChangeOutProjectRequest.getChangeOutMoney());
            }
            List<PayList> payLists = cardChangeListRequest.getPayLists();
            for (PayList payList : payLists) {
                ray= ray.add(payList.getPayMoney());
            }

            if(in.compareTo(out.add(ray).add(cardChangeList.getDebtMoney()==null?BigDecimal.valueOf(0):cardChangeList.getDebtMoney()))!=0){
                if(in.subtract(out.add(ray).add(cardChangeList.getDebtMoney()==null?BigDecimal.valueOf(0):cardChangeList.getDebtMoney())).abs().compareTo(balance)==1){
                    throw new SmsException(ResponseCode.MSG, "转入金额 不等于 支付金额+转出金额+欠款金额不相等");
                }
            }

            //校验欠款最大比例
            StoreParament storeParament1 = StoreParaUtils.getStorePara(cardChangeListRequest.getStoreId(), Constant.cardCangeListRatio);
            BigDecimal decimal = BigDecimal.valueOf(Double.valueOf(storeParament1.getParamentValue()));
            BigDecimal multiply = in.multiply(decimal.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP));
            if(cardChangeList.getDebtMoney().compareTo(multiply)==1){
                if(cardChangeList.getDebtMoney().subtract(multiply).abs().compareTo(balance)==1){
                    throw new SmsException(ResponseCode.MSG, "欠款最大比例为："+multiply+"元，当前欠款金额为："+cardChangeList.getDebtMoney());
                }
            }
        }

        Long id = new SnowflakeUtil(new Random().nextInt(1023)).nextId();
        cardChangeList.setId(id);

        String storeNum=ssmBaseStoreService.selectByPrimaryKey(cardChangeList.getStoreId()).getStoreNum();
//        BigDecimal reduce = cardChangeListRequest.getPayLists().stream().map(PayList::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add);

        String docNum = this.getDocNum(cardChangeList, 0,storeNum);
        cardChangeList.setDocNum(docNum);
        cardChangeList.setDocDate(new Date());
        //不走补单 正常开单 补单时间默认为开单时间
        if (0 == cardChangeList.getIsAddition()){
            cardChangeList.setAdditionDate(new Date());
        }
        if(cardChangeList.getChangeInPayMoney().add(cardChangeList.getDebtMoney()).compareTo(BigDecimal.valueOf(0))!=0){
            cardChangeList.setState(3);
        }else{
            cardChangeList.setState(0);
        }

        //设置录单人信息
        if (redisClient.hasKey(getStaffKey(cardChangeListRequest.getStaffPhone()))){
            StaffResponse staffResponse = redisClient.get(getStaffKey(cardChangeListRequest.getStaffPhone()));
            cardChangeList.setInputId(staffResponse.getId());
            cardChangeList.setInputBy(staffResponse.getStaffName());
        }
        Set<String> keys = redisClient.keys(getStaffKey(cardChangeListRequest.getStaffPhone()) + "*");
        //从redis查询 设置录单人信息 app使用
        if (keys.size() > 0){
            String key =  new ArrayList<>(keys).get(0);
            StaffResponse staffResponse = redisClient.get(key);
            cardChangeList.setInputId(staffResponse.getId());
            cardChangeList.setInputBy(staffResponse.getStaffName());
        }
//        //添加转入项目
        CardChangeInProject cardChangeInProject =null;
        CardChangeInProjectRequest cardChangeInProjectRequest = cardChangeListRequest.getCardChangeInProjectRequest();
        cardChangeInProjectRequest.setDebtMoney(cardChangeListRequest.getDebtMoney());
        cardChangeInProject = ssmCardChangeInProjectService.insert(cardChangeList, cardChangeInProjectRequest);


        //转出项目
        if(cardChangeList.getChangeInPayMoney().add(cardChangeList.getDebtMoney()).compareTo(BigDecimal.valueOf(0))==0){
            ssmCardChangeOutProjectService.insertLCNT(cardChangeList, cardChangeListRequest);
        }
        else {
            ssmCardChangeOutProjectService.insert(cardChangeList, cardChangeListRequest.getCardChangeOutProjectRequests());
        }
        //欠款 添加欠款记录
        if(cardChangeList.getState()==3){
            if (1 == cardChangeList.getIsDebt()){
                DebtListRequest debtListRequest = new DebtListRequest();
                //设置欠款单人
                BeanUtils.copyProperties(cardChangeList,debtListRequest);
                debtListRequest.setTradeId(cardChangeInProject.getProjectId());
                debtListRequest.setTradeName(cardChangeInProject.getProjectName());
                debtListRequest.setTradeMoney(cardChangeInProject.getChangeInMoney());
                debtListRequest.setDocId(id);
                debtListRequest.setDocNum(docNum);
                debtListRequest.setDocType(Constant.doc_type_card_change);
                debtListRequest.setAccountId(cardChangeInProject.getAccountId());
                debtListRequest.setStaffLists(cardChangeInProjectRequest.getStaffLists());
                debtListRequest.setState(0);
                debtListRequest.setDocDate(cardChangeList.getDocDate());
                debtListRequest.setRepayCount(cardChangeInProject.getCourseRestCount());
                debtListRequest.setRepayConsumeCount(cardChangeInProject.getCourseConsumeCount());
                ssmDebtService.addDebt(debtListRequest);
            }
        }
        try {
            i = dao.saveNotNull(cardChangeList);
        } catch (Exception e) {
            log.error("SsmCardChangeServiceImpl.add:", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        //添加现付支付方式
        List<PayList> payLists = cardChangeListRequest.getPayLists();
        if (null != payLists && payLists.size() > 0) {
            for (PayList payList : payLists) {
                payList.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
                payList.setDocId(docNum);
                payList.setType(Constant.doc_type_card_change);
                payList.setStoreId(cardChangeListRequest.getStoreId());
                payList.setPayDate(new Date());
                payList.setIsCancel(0);
            }
            ssmPayService.addPayList(payLists);
        }
        //将疗程单据信息添加到评价表
        MemberCsRequest memberCsRequest = new MemberCsRequest();
        BeanUtils.copyProperties(cardChangeList, memberCsRequest);
        memberCsRequest.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
        memberCsRequest.setDocId(id);
        memberCsRequest.setDocNum(docNum);
        memberCsRequest.setDocType(Constant.doc_type_card_change);
        memberCsRequest.setDocDate(cardChangeList.getDocDate());
        memberCsRequest.setTradeId(cardChangeInProject.getProjectId());
        memberCsRequest.setTradeName(cardChangeInProject.getProjectName());
        memberCsRequest.setTradeMoney(cardChangeInProject.getChangeInMoney());
        memberCsRequest.setTradeCount(cardChangeInProject.getChangeInTime());
        StringBuffer staffIds = new StringBuffer();
        StringBuffer staffNames = new StringBuffer();
        List<StaffRequest> staffLists = cardChangeInProjectRequest.getStaffLists();
        if (staffLists.size() > 0) {
            for (StaffRequest staffRequest : staffLists) {
                staffIds = staffIds.append(staffRequest.getId()).append(",");
                staffNames = staffNames.append(staffRequest.getStaffName()).append(",");
            }
        }
        memberCsRequest.setStaffIds(staffIds.toString());
        memberCsRequest.setStaffNames(staffNames.toString());
        ssmMemberCsService.addMemberCs(memberCsRequest);
        return i;
    }


    @Transactional(rollbackFor=Exception.class)
    @Override
    public int addNew(CardChangeListRequest cardChangeListRequest) throws SmsException {
        int i = 0;
        CardChangeList cardChangeList = new CardChangeList();
        BeanUtils.copyProperties(cardChangeListRequest, cardChangeList);

        if (cardChangeList.getDebtMoney()!=null && cardChangeList.getIsDebt()==0){
            throw new SmsException(ResponseCode.MSG, "欠款字段传参错误！");
        }
        //判断支付金额是否和成交金额相等 支付金额+转出金额+欠款金额
        StoreParament storeParament = StoreParaUtils.getStorePara(cardChangeListRequest.getStoreId(), Constant.cardCangeListDebt);
        if("0".equals(storeParament.getParamentValue())){
            BigDecimal amount = BigDecimalUtils.add(BigDecimalUtils.add(cardChangeList.getChangeInPayMoney(), cardChangeList.getChangeOutMoney()), cardChangeList.getDebtMoney());
            if (BigDecimalUtils.compareTo(amount, cardChangeList.getChangeInMoney()) != 0) {
                throw new SmsException(ResponseCode.MSG, "总金额和成交金额不相等");
            }
        }else{
            BigDecimal out = BigDecimalUtils.bigDecimal("0");
            BigDecimal in = cardChangeListRequest.getCardChangeInProjectRequest().getChangeInMoney();
            BigDecimal ray =  BigDecimalUtils.bigDecimal("0");

            List<CardChangeOutProjectRequest> cardChangeOutProjectRequests = cardChangeListRequest.getCardChangeOutProjectRequests();
            for (CardChangeOutProjectRequest cardChangeOutProjectRequest : cardChangeOutProjectRequests) {
                out=out.add(cardChangeOutProjectRequest.getChangeOutMoney());
            }
            List<PayList> payLists = cardChangeListRequest.getPayLists();
            for (PayList payList : payLists) {
                ray= ray.add(payList.getPayMoney());
            }

            if(in.compareTo(out.add(ray).add(cardChangeList.getDebtMoney()))!=0){
                throw new SmsException(ResponseCode.MSG, "转入金额 不等于 支付金额+转出金额+欠款金额不相等");
            }

            //校验欠款最大比例
            StoreParament storeParament1 = StoreParaUtils.getStorePara(cardChangeListRequest.getStoreId(), Constant.cardCangeListRatio);
            BigDecimal decimal = BigDecimal.valueOf(Double.valueOf(storeParament1.getParamentValue()));
            BigDecimal multiply = in.multiply(decimal.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP));
            if(cardChangeList.getDebtMoney().compareTo(multiply)==1){
                throw new SmsException(ResponseCode.MSG, "欠款最大比例为："+multiply+"元，当前欠款金额为："+cardChangeList.getDebtMoney());
            }
        }

        Long id = new SnowflakeUtil(new Random().nextInt(1023)).nextId();
        cardChangeList.setId(id);

        String storeNum=ssmBaseStoreService.selectByPrimaryKey(cardChangeList.getStoreId()).getStoreNum();

        String docNum = this.getDocNum(cardChangeList, 0,storeNum);
        cardChangeList.setDocNum(docNum);
        cardChangeList.setDocDate(new Date());
        //不走补单 正常开单 补单时间默认为开单时间
        if (0 == cardChangeList.getIsAddition()){
            cardChangeList.setAdditionDate(new Date());
        }
        if(cardChangeList.getChangeInPayMoney().compareTo(BigDecimal.valueOf(0))!=0){
            cardChangeList.setState(3);
        }else{
            cardChangeList.setState(0);
        }

        //设置录单人信息
        if (redisClient.hasKey(getStaffKey(cardChangeListRequest.getStaffPhone()))){
            StaffResponse staffResponse = redisClient.get(getStaffKey(cardChangeListRequest.getStaffPhone()));
            cardChangeList.setInputId(staffResponse.getId());
            cardChangeList.setInputBy(staffResponse.getStaffName());
        }
        Set<String> keys = redisClient.keys(getStaffKey(cardChangeListRequest.getStaffPhone()) + "*");
        //从redis查询 设置录单人信息 app使用
        if (keys.size() > 0){
            String key =  new ArrayList<>(keys).get(0);
            StaffResponse staffResponse = redisClient.get(key);
            cardChangeList.setInputId(staffResponse.getId());
            cardChangeList.setInputBy(staffResponse.getStaffName());
        }
//        //添加转入项目

        CardChangeInProjectRequest cardChangeInProjectRequest = cardChangeListRequest.getCardChangeInProjectRequest();
        cardChangeInProjectRequest.setPayLists(cardChangeListRequest.getPayLists());
        CardChangeInProject cardChangeInProject = ssmCardChangeInProjectService.insertNew(cardChangeList, cardChangeInProjectRequest);
        //添加转出项目
        ssmCardChangeOutProjectService.insertNew(cardChangeList, cardChangeListRequest.getCardChangeOutProjectRequests());
        //欠款 添加欠款记录
        if(cardChangeList.getState()==3){
            if (1 == cardChangeList.getIsDebt()){
                DebtListRequest debtListRequest = new DebtListRequest();
                BeanUtils.copyProperties(cardChangeList,debtListRequest);
                debtListRequest.setTradeId(cardChangeInProject.getProjectId());
                debtListRequest.setTradeName(cardChangeInProject.getProjectName());
                debtListRequest.setTradeMoney(cardChangeInProject.getChangeInMoney());
                debtListRequest.setDocId(id);
                debtListRequest.setDocNum(docNum);
                debtListRequest.setDocType(Constant.doc_type_card_change);
                debtListRequest.setAccountId(cardChangeInProject.getAccountId());
                debtListRequest.setStaffLists(cardChangeInProjectRequest.getStaffLists());
                debtListRequest.setState(0);
                debtListRequest.setDocDate(cardChangeList.getDocDate());
                debtListRequest.setRepayCount(cardChangeInProject.getCourseRestCount());
                debtListRequest.setRepayConsumeCount(cardChangeInProject.getCourseConsumeCount());
                ssmDebtService.addDebt(debtListRequest);
            }
        }
        try {
            i = dao.saveNotNull(cardChangeList);
        } catch (Exception e) {
            log.error("SsmCardChangeServiceImpl.add:", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        //添加现付支付方式
        List<PayList> payLists = cardChangeListRequest.getPayLists();
        if (null != payLists && payLists.size() > 0) {
            for (PayList payList : payLists) {
                payList.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
                payList.setDocId(String.valueOf(id));
                payList.setType(Constant.doc_type_card_change);
                payList.setStoreId(cardChangeListRequest.getStoreId());
                payList.setIsCancel(0);
            }
            ssmPayService.addPayList(payLists);
        }
        //将疗程单据信息添加到评价表
        MemberCsRequest memberCsRequest = new MemberCsRequest();
        BeanUtils.copyProperties(cardChangeList, memberCsRequest);
        memberCsRequest.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
        memberCsRequest.setDocId(id);
        memberCsRequest.setDocNum(docNum);
        memberCsRequest.setDocType(Constant.doc_type_card_change);
        memberCsRequest.setDocDate(cardChangeList.getDocDate());
        memberCsRequest.setTradeId(cardChangeInProject.getProjectId());
        memberCsRequest.setTradeName(cardChangeInProject.getProjectName());
        memberCsRequest.setTradeMoney(cardChangeInProject.getChangeInMoney());
        memberCsRequest.setTradeCount(cardChangeInProject.getChangeInTime());
        StringBuffer staffIds = new StringBuffer();
        StringBuffer staffNames = new StringBuffer();
        List<StaffRequest> staffLists = cardChangeInProjectRequest.getStaffLists();
        if (staffLists.size() > 0) {
            for (StaffRequest staffRequest : staffLists) {
                staffIds = staffIds.append(staffRequest.getId()).append(",");
                staffNames = staffNames.append(staffRequest.getStaffName()).append(",");
            }
        }
        memberCsRequest.setStaffIds(staffIds.toString());
        memberCsRequest.setStaffNames(staffNames.toString());
        ssmMemberCsService.addMemberCs(memberCsRequest);
        return i;
    }


    @Override
    public int updateStaff(CardChangeListRequest cardChangeListRequest) throws SmsException {

        StoreParament storeParament = StoreParaUtils.getStorePara(cardChangeListRequest.getStoreId(), Constant.editOrderNum);
        int days = (int) DateUtils.getDayDiff(cardChangeListRequest.getDocDate(), new Date());
        if(!"0".equals(storeParament.getParamentValue())) {
            if (Integer.parseInt(storeParament.getParamentValue()) < days) {
                throw new SmsException(ResponseCode.CANCEL_NOT_PERMISSIONS, "单据超过允许修改时间");
            }
        }

        List<PayList> payLists = cardChangeListRequest.getPayLists();
        if(payLists!=null && payLists.size()>0){
            for (PayList payList : payLists) {
                BaseCollectionType baseCollectionType = ssmCollectionTypeService.selectByPrimaryKey(payList.getPayId());
                payList.setPayName(baseCollectionType.getCollectionTypeName());
                ssmPayService.updateByPrimaryKey(payList);
            }
        }
        int i = 0;
        try {
            if (null != cardChangeListRequest.getCardChangeOutProjectRequests() && cardChangeListRequest.getCardChangeOutProjectRequests().size() > 0)
                i = ssmCardChangeOutProjectService.updateStaffLCNT(cardChangeListRequest.getCardChangeOutProjectRequests());

            if (null != cardChangeListRequest.getCardChangeInProjectRequest())
               i = ssmCardChangeInProjectService.updateStaff(cardChangeListRequest.getCardChangeInProjectRequest());
        }catch (Exception e){
            log.error("SsmCardChangeServiceImpl.updateStaff:",e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        return i;
    }


    @Override
    public int cancel(CardChangeListRequest cardChangeListRequest) throws SmsException {
        int i = 0;

//        CardChangeList cardChangeList = new CardChangeList();
//        BeanUtils.copyProperties(cardChangeListRequest, cardChangeList);
        CardChangeList cardChangeList = dao.selectByPrimaryKey(cardChangeListRequest.getId());
        //判断时间是否超过允许作废时间
        StoreParament storeParament = StoreParaUtils.getStorePara(cardChangeListRequest.getStoreId(),Constant.service_ticke);
        Long days =  DateUtils.getDayDiff(cardChangeList.getDocDate(),new Date());
        if(!"0".equals(storeParament.getParamentValue())) {
            if (days.longValue() > Long.parseLong(storeParament.getParamentValue())) {
                throw new SmsException(ResponseCode.CANCEL_NOT_PERMISSION, "单据超过允许作废时间");
            }
        }
        //修改疗程单据状态
        cardChangeList.setIsCancel(1);
        cardChangeList.setCancelDate(new Date());
        //设置作废人信息
        if (redisClient.hasKey(getStaffKey(cardChangeListRequest.getStaffPhone()))){
            StaffResponse staffResponse = redisClient.get(getStaffKey(cardChangeListRequest.getStaffPhone()));
            cardChangeList.setCancelId(staffResponse.getId());
            cardChangeList.setCancelBy(staffResponse.getStaffName());
        }
        Set<String> keys = redisClient.keys(getStaffKey(cardChangeListRequest.getStaffPhone()) + "*");
        //从redis查询 设置作废人信息 app使用
        if (keys.size() > 0){
            String key =  new ArrayList<>(keys).get(0);
            StaffResponse staffResponse = redisClient.get(key);
            cardChangeList.setCancelId(staffResponse.getId());
            cardChangeList.setCancelBy(staffResponse.getStaffName());
        }
        //转入疗程作废 账户扣减次数
        ssmCardChangeInProjectService.cancel(cardChangeList);
        //转出疗程作废 账户添加次数
        ssmCardChangeOutProjectService.cancel(cardChangeList);
        //欠款 删除欠款记录
        if (1 == cardChangeList.getIsDebt()){
            DebtListRequest debtListRequest = new DebtListRequest();
            debtListRequest.setDocId(cardChangeList.getId());
            debtListRequest.setMemberId(cardChangeList.getMemberId());
            debtListRequest.setStoreId(cardChangeList.getStoreId());
            ssmDebtService.deleteDebt(debtListRequest);
        }
        try {
            i = dao.updateByPrimaryKeySelective(cardChangeList);
            Salesman salesman = new Salesman();
            salesman.setOrderNum(String.valueOf(cardChangeList.getDocNum()));
            salesman.setOrderType(3);
            List<Salesman> salesmen = ssmSalesmanService.selectList(salesman);
            for (Salesman salesman1 : salesmen) {
                salesman1.setState(1);
                ssmSalesmanService.updateNotNull(salesman1);
            }
        }catch (Exception e){
            log.error("SsmCardChangeServiceImpl.cancel:", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        //将评价单进行删除操作
        MemberCs memberCs = new MemberCs();
        memberCs.setDocId(cardChangeList.getId());
        ssmMemberCsService.delete(memberCs);
        return i;
    }

    @Override
    public int NTAdd(CardChangeListRequest cardChangeListRequest) throws SmsException {
        int i = 0;
        StoreParament storeParament = StoreParaUtils.getStorePara(cardChangeListRequest.getStoreId(), Constant.withinBalance);
        //判断是否超出容差
        if (null != storeParament && BigDecimalUtils.compareTo(BigDecimalUtils.bigDecimal(storeParament.getParamentValue()),
                BigDecimalUtils.subtract(cardChangeListRequest.getChangeOutMoney(), cardChangeListRequest.getChangeInMoney()).abs()) < 0){
            throw new SmsException(ResponseCode.PRICE_COMPARE_MORE_THAN, "差异金额超过内调容差金额");
        }
        CardChangeList cardChangeList = new CardChangeList();
        BeanUtils.copyProperties(cardChangeListRequest, cardChangeList);
        Long id = new SnowflakeUtil(new Random().nextInt(1023)).nextId();
        cardChangeList.setId(id);
        String docNum = this.getDocNum(cardChangeList, 0,null);
        cardChangeList.setDocNum(docNum);
        cardChangeList.setDocDate(new Date());
        cardChangeList.setState(0);
        //不走补单 正常开单 补单时间默认为开单时间
        if (0 == cardChangeList.getIsAddition()){
            cardChangeList.setAdditionDate(new Date());
        }
        //添加转入项目
        CardChangeInProjectRequest cardChangeInProjectRequest = cardChangeListRequest.getCardChangeInProjectRequest();
        CardChangeInProject cardChangeInProject = ssmCardChangeInProjectService.insertNT(cardChangeList, cardChangeInProjectRequest);
        //添加转出项目
        ssmCardChangeOutProjectService.insertNT(cardChangeList, cardChangeListRequest.getCardChangeOutProjectRequests());
        //设置录单人信息
        if (redisClient.hasKey(getStaffKey(cardChangeListRequest.getStaffPhone()))){
            StaffResponse staffResponse = redisClient.get(getStaffKey(cardChangeListRequest.getStaffPhone()));
            cardChangeList.setInputId(staffResponse.getId());
            cardChangeList.setInputBy(staffResponse.getStaffName());
        }
        Set<String> keys = redisClient.keys(getStaffKey(cardChangeListRequest.getStaffPhone()) + "*");
        //从redis查询 设置录单人信息 app使用
        if (keys.size() > 0){
            String key =  new ArrayList<>(keys).get(0);
            StaffResponse staffResponse = redisClient.get(key);
            cardChangeList.setInputId(staffResponse.getId());
            cardChangeList.setInputBy(staffResponse.getStaffName());
        }
        try {
            i = dao.saveNotNull(cardChangeList);
        } catch (Exception e) {
            log.error("SsmCardChangeServiceImpl.NTAdd:", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        return i;
    }

    @Override
    public int sendAudit(CardChangeListRequest cardChangeListRequest) throws SmsException {
        int i = 0;
        CardChangeList cardChangeList = dao.selectByPrimaryKey(cardChangeListRequest.getId());

        //校验单据状态
        if ( cardChangeList.getState() == 3 || cardChangeList.getState() == 1) {
            throw new SmsException(ResponseCode.NOT_ALLOW_UPDATE_STATE, "送审");
        }
        cardChangeList.setState(1);//送审 修改状态
        //锁定账户
        CardChangeOutProject cardChangeOutProject = new CardChangeOutProject();
        cardChangeOutProject.setDocNum(cardChangeList.getDocNum());
        cardChangeOutProject.setStoreId(cardChangeList.getStoreId());
        List<CardChangeOutProject> cardChangeOutProjectList = ssmCardChangeOutProjectService.select(cardChangeOutProject);
        cardChangeOutProjectList.stream().forEach(cardChangeOutProject1 -> ssmCourseAccountService.updateState(cardChangeOutProject1.getAccountId(), 0));

        CardChangeInProject cardChangeInProject = new CardChangeInProject();
        cardChangeInProject.setDocNum(cardChangeList.getDocNum());
        cardChangeInProject.setStoreId(cardChangeList.getStoreId());
        cardChangeInProject = ssmCardChangeInProjectService.selectOne(cardChangeInProject);
        ssmCourseAccountService.updateState(cardChangeInProject.getAccountId(), 0);

        i = dao.updateByPrimaryKeySelective(cardChangeList);
        return i;
    }

    @Override
    public int revoke(CardChangeListRequest cardChangeListRequest) throws SmsException {
        int i = 0;
        CardChangeList cardChangeList = dao.selectByPrimaryKey(cardChangeListRequest.getId());

        //校验单据状态
        if ( cardChangeList.getState() != 1) {
            throw new SmsException(ResponseCode.NOT_ALLOW_UPDATE_STATE, "回收");
        }
        cardChangeList.setState(2);//回收 修改状态
        //锁定账户
        CardChangeOutProject cardChangeOutProject = new CardChangeOutProject();
        cardChangeOutProject.setDocNum(cardChangeList.getDocNum());
        cardChangeOutProject.setStoreId(cardChangeList.getStoreId());
        List<CardChangeOutProject> cardChangeOutProjectList = ssmCardChangeOutProjectService.select(cardChangeOutProject);
        cardChangeOutProjectList.stream().forEach(cardChangeOutProject1 -> ssmCourseAccountService.updateState(cardChangeOutProject1.getAccountId(), 1));

        CardChangeInProject cardChangeInProject = new CardChangeInProject();
        cardChangeInProject.setDocNum(cardChangeList.getDocNum());
        cardChangeInProject.setStoreId(cardChangeList.getStoreId());
        cardChangeInProject = ssmCardChangeInProjectService.selectOne(cardChangeInProject);
        ssmCourseAccountService.updateState(cardChangeInProject.getAccountId(), 1);

        i = dao.updateByPrimaryKeySelective(cardChangeList);
        return i;
    }

    @Override
    public int audit(CardChangeListRequest cardChangeListRequest) throws SmsException {
        int i = 0;
        CardChangeList cardChangeList = dao.selectByPrimaryKey(cardChangeListRequest.getId());

        //设置审核人信息
        if (redisClient.hasKey(getStaffKey(cardChangeListRequest.getStaffPhone()))){
            StaffResponse staffResponse = redisClient.get(getStaffKey(cardChangeListRequest.getStaffPhone()));
            cardChangeList.setAuditId(staffResponse.getId());
            cardChangeList.setAuditBy(staffResponse.getStaffName());
        }
        Set<String> keys = redisClient.keys(getStaffKey(cardChangeListRequest.getStaffPhone()) + "*");
        //从redis查询 设置审核人信息 app使用
        if (keys.size() > 0){
            String key =  new ArrayList<>(keys).get(0);
            StaffResponse staffResponse = redisClient.get(key);
            cardChangeList.setAuditId(staffResponse.getId());
            cardChangeList.setAuditBy(staffResponse.getStaffName());
        }
        cardChangeList.setAuditDate(new Date());
        cardChangeList.setState(3);
        ssmCardChangeOutProjectService.audit(cardChangeList);
        ssmCardChangeInProjectService.audit(cardChangeList);
        try {
            i = dao.updateByPrimaryKeySelective(cardChangeList);
        } catch (Exception e) {
            log.error("SsmCardChangeServiceImpl.audit", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        return i;
    }

    @Override
    public int unAudit(CardChangeListRequest cardChangeListRequest) throws SmsException {
        int i = 0;
        CardChangeList cardChangeList = dao.selectByPrimaryKey(cardChangeListRequest.getId());
        cardChangeList.setState(4);
        ssmCardChangeOutProjectService.unAudit(cardChangeList);
        ssmCardChangeInProjectService.unAudit(cardChangeList);
        try {
            i = dao.updateByPrimaryKeySelective(cardChangeList);
        } catch (Exception e) {
            log.error("SsmCardChangeServiceImpl.unAudit", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        return i;
    }

    public String getDocNum(CardChangeList cardChangeList, int type,String storeNum){
        //查询数据库门店编码最新的一个
        String ymdDate = DateUtils.YMDFormat(new Date());
        Example example = new Example(CardChangeList.class);
        BigDecimal changeInPayMoney = cardChangeList.getChangeInPayMoney();
        String docNum = "";
        if(changeInPayMoney.add(cardChangeList.getDebtMoney()).compareTo(BigDecimal.valueOf(0))==1){
            docNum = "ZLC";
        }else
            docNum = "LCNT";
        Example.Criteria criteria = example.createCriteria();
        //按门店编码降序排列
        example.setOrderByClause("doc_num desc");
        //通过时间模糊查询
        if (type == 0){
            //加价转疗程
           // criteria.andLike("docNum","JJ" + ymdDate + "%");
            criteria.andLike("docNum", docNum+storeNum+ymdDate + "%");
        }
        else{
            //内调
            //criteria.andLike("docNum","NT" + ymdDate + "%");
            criteria.andLike("docNum","%" +ymdDate + "%");
        }
        criteria.andEqualTo("storeId", cardChangeList.getStoreId());
        List<CardChangeList> cardChangeLists = dao.selectByExample(example);

        String num;
        int mm = 0;
        if (cardChangeLists != null && cardChangeLists.size() > 0) {
            CardChangeList changeList = cardChangeLists.get(0);
            int a=storeNum.length()+3;
            mm = Integer.parseInt(changeList.getDocNum().substring(10+a)) + 1;
            if (mm < 10){
                num = "00" + mm;
            }else if (mm < 100){
                num = "0" + mm;
            }else {
                num = String.valueOf(mm);
            }
            if(storeNum!=null){
                docNum += storeNum + ymdDate + num;
            }else{
                docNum +=   ymdDate + num;
            }


        }else {
            num = "001" ;
            if(storeNum!=null){
                docNum += storeNum + ymdDate + num;
            }else{
                docNum +=   ymdDate + num;
            }
        }
        return docNum;
    }

    public String getStaffKey(String phone){
        return staffKey + phone;
    }

    @Override
    public List<CardChangeInProjectResponse> selectList(Long storeId, String date){
        Example example = new Example(CardChangeList.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId",storeId);
        criteria.andLike("docDate", date + "%");
        criteria.andEqualTo("state", 3);
        List<CardChangeList> cardChangeLists = dao.selectByExample(example);
        List<CardChangeInProject> cardChangeInProjects = new ArrayList<>();
        for (CardChangeList cardChangeList : cardChangeLists) {
            Example examples = new Example(CardChangeInProject.class);
            Example.Criteria criterias = examples.createCriteria();
            criterias.andEqualTo("docNum",cardChangeList.getDocNum());
            List<CardChangeInProject> cardChangeInProjectlist = ssmCardChangeInProjectService.selectByExample(examples);


            for (CardChangeInProject cardChangeInProject : cardChangeInProjectlist) {
                cardChangeInProjects.add(cardChangeInProject);
            }
        }
        List<CardChangeInProjectResponse> listResponses = new ArrayList<>();
        for (CardChangeInProject cardChangeInProject :cardChangeInProjects) {



            CardChangeInProjectResponse courseListResponse = new CardChangeInProjectResponse();
            BeanUtils.copyProperties(cardChangeInProject,courseListResponse);

            CardChangeOutProject cardChangeOutProject=new CardChangeOutProject();
            cardChangeOutProject.setDocNum(cardChangeInProject.getDocNum());
            List<CardChangeOutProject> cardChangeOutProjects=ssmCardChangeOutProjectService.select(cardChangeOutProject);
            //todo
            cardChangeInProject.setChangeOutMoney(BigDecimal.valueOf(0));
            for (CardChangeOutProject changeOutProject : cardChangeOutProjects) {
                CourseAccount courseAccount = ssmCourseAccountService.selectByPrimaryKey(changeOutProject.getAccountId());
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String courseNum = courseAccount.getCourseNum();
                if(courseNum.startsWith("ZLC")||courseNum.startsWith("LCNT")){
                    CardChangeInProject inProject = new CardChangeInProject();
                    inProject.setDocNum(courseNum);
                    inProject.setProjectId(changeOutProject.getCourseProjectId());
                    CardChangeInProject changeInProject = ssmCardChangeInProjectService.selectOne(inProject);
                    List<AchiCommEntity> achiCommList =new ArrayList<>();
                    achiCommList.addAll(this.getAchiCommListKJ(changeInProject,cardChangeInProject,changeOutProject));
//                    //有欠款查询欠款单
//                    if(changeInProject.getDebtMoney().compareTo(BigDecimal.valueOf(0))==1){
//                        RepayTradeList repayTradeList = new RepayTradeList();
//                        repayTradeList.setDocNum(courseNum);
//                        List<RepayTradeList> repayTradeLists = ssmRepayTradeService.selectList(repayTradeList);
//                        for (RepayTradeList tradeList : repayTradeLists) {
//                            if(tradeList.getTradeId().equals(changeInProject.getProjectId())){
//                                achiCommList.addAll(this.getAchiCommList(tradeList,cardChangeInProject));
//                            }
//                        }
//                    }
                    for (AchiCommEntity achiCommEntity : achiCommList) {
                        achiCommEntity.setDocId(changeOutProject.getId());
                    }
                    changeOutProject.setEntities(achiCommList);
//                    List<AchiCommEntity> achiCommEntityList = new ArrayList<>();
//                    changeOutProject.setEntities(achiCommEntityList);

                }
                else if(courseNum.startsWith("LC")){
                    String substring = courseNum.substring(courseNum.length() - 11, courseNum.length() - 3);
                    StrBuilder strBuilder = new StrBuilder(substring);
                    Date parse;
                    StrBuilder insert = strBuilder.insert(6, "-").insert(4, "-");
                    try {
                        parse = dateFormat.parse(String.valueOf(insert));
                    } catch (ParseException e) {
                        throw new RuntimeException(e);
                    }
                    CourseListRequest courseListRequest = new CourseListRequest();
                    courseListRequest.setDate(parse);
                    courseListRequest.setDocId(courseNum);
                    courseListRequest.setProjctId(changeOutProject.getCourseProjectId());
                    List<CourseList> courseListList = ssmCourseDao.selectCourseOne(courseListRequest);
                    CourseList courseList = courseListList.get(0);
                    List<AchiCommEntity> achiCommList =new ArrayList<>();
                    achiCommList.addAll(this.getAchiCommList(courseList,cardChangeInProject,changeOutProject));
                    //有欠款查询欠款单
//                    if(courseList.getDebtMoney().compareTo(BigDecimal.valueOf(0))==1){
//                        RepayTradeList repayTradeList = new RepayTradeList();
//                        repayTradeList.setDocNum(courseNum);
//                        List<RepayTradeList> repayTradeLists = ssmRepayTradeService.selectList(repayTradeList);
//                        for (RepayTradeList tradeList : repayTradeLists) {
//                            if(tradeList.getTradeId().equals(courseList.getProjctId())){
//                                achiCommList.addAll(this.getAchiCommList(tradeList,cardChangeInProject));
//                            }
//                        }
//                    }
                    changeOutProject.setEntities(achiCommList);

                }
                else {
                    changeOutProject.setEntities(new ArrayList<>());
                }
            }

            courseListResponse.setOutProjects(cardChangeOutProjects);
            BigDecimal cooperationCashCarAchisum=new BigDecimal("0");//合作业绩
            for(CardChangeOutProject cardChangeOutProject1:cardChangeOutProjects){
                BaseProject baseProject = ssmProjectService.selectByPrimaryKey(cardChangeOutProject1.getCourseProjectId());
                //isCooperation 比例brokerage 1是比例 0是固定smokeCommissionWay
                if(baseProject.getIsCooperation()==1){
                    if(baseProject.getSmokeCommissionWay()==1){//合作按比例
                        cooperationCashCarAchisum=cooperationCashCarAchisum.add(baseProject.getBrokerage().divide(BigDecimal.valueOf(100)).multiply(cardChangeOutProject1.getChangeOutMoney()));
                    }else{//合作按固定
                        cooperationCashCarAchisum=cooperationCashCarAchisum.add(baseProject.getBrokerage());
                    }
                }
            }
            cardChangeInProject.setChangeOutMoney(cardChangeInProject.getChangeOutMoney().subtract(cooperationCashCarAchisum));

            //设置业务人员列表
            List<AchiCommEntity> entities = this.getAchiCommListByJz(cardChangeInProject);
            courseListResponse.setEntities(entities);
            for (AchiCommEntity entity : entities) {
                entity.setDocId(cardChangeInProject.getId());
                BaseProject baseProject = new BaseProject();
                baseProject.setId(Long.valueOf(entity.getProjectId()));
                BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                entity.setProjectId(baseProject1.getProjectNum());
            }
            listResponses.add(courseListResponse);
        }
        return listResponses;
    }

    @Override
    public List<CardChangeInProjectResponse> selectListByStartTimeAndEndTime(Long storeId, String date,Date startTime,Date endTime){
        Example example = new Example(CardChangeList.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId",storeId);
//        criteria.andLike("docDate", date + "%");
        criteria.andBetween("docDate",startTime,endTime);
        criteria.andEqualTo("state", 3);
        List<CardChangeList> cardChangeLists = dao.selectByExample(example);
        List<CardChangeInProject> cardChangeInProjects = new ArrayList<>();
        for (CardChangeList cardChangeList : cardChangeLists) {
            Example examples = new Example(CardChangeInProject.class);
            Example.Criteria criterias = examples.createCriteria();
            criterias.andEqualTo("docNum",cardChangeList.getDocNum());
            List<CardChangeInProject> cardChangeInProjectlist = ssmCardChangeInProjectService.selectByExample(examples);


            for (CardChangeInProject cardChangeInProject : cardChangeInProjectlist) {
                cardChangeInProjects.add(cardChangeInProject);
            }
        }
        List<CardChangeInProjectResponse> listResponses = new ArrayList<>();
        for (CardChangeInProject cardChangeInProject :cardChangeInProjects) {



            CardChangeInProjectResponse courseListResponse = new CardChangeInProjectResponse();
            BeanUtils.copyProperties(cardChangeInProject,courseListResponse);

            CardChangeOutProject cardChangeOutProject=new CardChangeOutProject();
            cardChangeOutProject.setDocNum(cardChangeInProject.getDocNum());
            List<CardChangeOutProject> cardChangeOutProjects=ssmCardChangeOutProjectService.select(cardChangeOutProject);
            //todo
            cardChangeInProject.setChangeOutMoney(BigDecimal.valueOf(0));
            for (CardChangeOutProject changeOutProject : cardChangeOutProjects) {
                CourseAccount courseAccount = ssmCourseAccountService.selectByPrimaryKey(changeOutProject.getAccountId());
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String courseNum = courseAccount.getCourseNum();
                if(courseNum.startsWith("ZLC")||courseNum.startsWith("LCNT")){
                    CardChangeInProject inProject = new CardChangeInProject();
                    inProject.setDocNum(courseNum);
                    inProject.setProjectId(changeOutProject.getCourseProjectId());
                    CardChangeInProject changeInProject = ssmCardChangeInProjectService.selectOne(inProject);
                    List<AchiCommEntity> achiCommList =new ArrayList<>();
                    achiCommList.addAll(this.getAchiCommListKJ(changeInProject,cardChangeInProject,changeOutProject));
//                    //有欠款查询欠款单
//                    if(changeInProject.getDebtMoney().compareTo(BigDecimal.valueOf(0))==1){
//                        RepayTradeList repayTradeList = new RepayTradeList();
//                        repayTradeList.setDocNum(courseNum);
//                        List<RepayTradeList> repayTradeLists = ssmRepayTradeService.selectList(repayTradeList);
//                        for (RepayTradeList tradeList : repayTradeLists) {
//                            if(tradeList.getTradeId().equals(changeInProject.getProjectId())){
//                                achiCommList.addAll(this.getAchiCommList(tradeList,cardChangeInProject));
//                            }
//                        }
//                    }
                    for (AchiCommEntity achiCommEntity : achiCommList) {
                        achiCommEntity.setDocId(changeOutProject.getId());
                    }
                    changeOutProject.setEntities(achiCommList);
//                    List<AchiCommEntity> achiCommEntityList = new ArrayList<>();
//                    changeOutProject.setEntities(achiCommEntityList);

                }
                else if(courseNum.startsWith("LC")){
                    String substring = courseNum.substring(courseNum.length() - 11, courseNum.length() - 3);
                    StrBuilder strBuilder = new StrBuilder(substring);
                    Date parse;
                    StrBuilder insert = strBuilder.insert(6, "-").insert(4, "-");
                    try {
                        parse = dateFormat.parse(String.valueOf(insert));
                    } catch (ParseException e) {
                        throw new RuntimeException(e);
                    }
                    CourseListRequest courseListRequest = new CourseListRequest();
                    courseListRequest.setDate(parse);
                    courseListRequest.setDocId(courseNum);
                    courseListRequest.setProjctId(changeOutProject.getCourseProjectId());
                    List<CourseList> courseListList = ssmCourseDao.selectCourseOne(courseListRequest);
                    CourseList courseList = courseListList.get(0);
                    List<AchiCommEntity> achiCommList =new ArrayList<>();
                    achiCommList.addAll(this.getAchiCommList(courseList,cardChangeInProject,changeOutProject));
                    //有欠款查询欠款单
//                    if(courseList.getDebtMoney().compareTo(BigDecimal.valueOf(0))==1){
//                        RepayTradeList repayTradeList = new RepayTradeList();
//                        repayTradeList.setDocNum(courseNum);
//                        List<RepayTradeList> repayTradeLists = ssmRepayTradeService.selectList(repayTradeList);
//                        for (RepayTradeList tradeList : repayTradeLists) {
//                            if(tradeList.getTradeId().equals(courseList.getProjctId())){
//                                achiCommList.addAll(this.getAchiCommList(tradeList,cardChangeInProject));
//                            }
//                        }
//                    }
                    changeOutProject.setEntities(achiCommList);

                }
                else {
                    changeOutProject.setEntities(new ArrayList<>());
                }
            }

            courseListResponse.setOutProjects(cardChangeOutProjects);
            BigDecimal cooperationCashCarAchisum=new BigDecimal("0");//合作业绩
            for(CardChangeOutProject cardChangeOutProject1:cardChangeOutProjects){
                BaseProject baseProject = ssmProjectService.selectByPrimaryKey(cardChangeOutProject1.getCourseProjectId());
                //isCooperation 比例brokerage 1是比例 0是固定smokeCommissionWay
                if(baseProject.getIsCooperation()==1){
                    if(baseProject.getSmokeCommissionWay()==1){//合作按比例
                        cooperationCashCarAchisum=cooperationCashCarAchisum.add(baseProject.getBrokerage().divide(BigDecimal.valueOf(100)).multiply(cardChangeOutProject1.getChangeOutMoney()));
                    }else{//合作按固定
                        cooperationCashCarAchisum=cooperationCashCarAchisum.add(baseProject.getBrokerage());
                    }
                }
            }
            cardChangeInProject.setChangeOutMoney(cardChangeInProject.getChangeOutMoney().subtract(cooperationCashCarAchisum));

            //设置业务人员列表
            List<AchiCommEntity> entities = this.getAchiCommListByJz(cardChangeInProject);
            courseListResponse.setEntities(entities);
            for (AchiCommEntity entity : entities) {
                entity.setDocId(cardChangeInProject.getId());
                BaseProject baseProject = new BaseProject();
                baseProject.setId(Long.valueOf(entity.getProjectId()));
                BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                entity.setProjectId(baseProject1.getProjectNum());
            }
            listResponses.add(courseListResponse);
        }
        return listResponses;
    }
    @Override
    public List<CardChangeInProjectResponse> selectListByStartTimeAndEndTime(Long storeId,Date startTime,Date endTime){
        Example example = new Example(CardChangeList.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId",storeId);
//        criteria.andLike("docDate", date + "%");
        criteria.andBetween("docDate",startTime,endTime);
        criteria.andEqualTo("state", 3);
        List<CardChangeList> cardChangeLists = dao.selectByExample(example);
        List<CardChangeInProject> cardChangeInProjects = new ArrayList<>();
        for (CardChangeList cardChangeList : cardChangeLists) {
            Example examples = new Example(CardChangeInProject.class);
            Example.Criteria criterias = examples.createCriteria();
            criterias.andEqualTo("docNum",cardChangeList.getDocNum());
            List<CardChangeInProject> cardChangeInProjectlist = ssmCardChangeInProjectService.selectByExample(examples);


            for (CardChangeInProject cardChangeInProject : cardChangeInProjectlist) {
                cardChangeInProjects.add(cardChangeInProject);
            }
        }
        List<CardChangeInProjectResponse> listResponses = new ArrayList<>();
        for (CardChangeInProject cardChangeInProject :cardChangeInProjects) {



            CardChangeInProjectResponse courseListResponse = new CardChangeInProjectResponse();
            BeanUtils.copyProperties(cardChangeInProject,courseListResponse);

            CardChangeOutProject cardChangeOutProject=new CardChangeOutProject();
            cardChangeOutProject.setDocNum(cardChangeInProject.getDocNum());
            List<CardChangeOutProject> cardChangeOutProjects=ssmCardChangeOutProjectService.select(cardChangeOutProject);
            //todo
            cardChangeInProject.setChangeOutMoney(BigDecimal.valueOf(0));
            for (CardChangeOutProject changeOutProject : cardChangeOutProjects) {
                CourseAccount courseAccount = ssmCourseAccountService.selectByPrimaryKey(changeOutProject.getAccountId());
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String courseNum = courseAccount.getCourseNum();
                if(courseNum.startsWith("ZLC")||courseNum.startsWith("LCNT")){
                    CardChangeInProject inProject = new CardChangeInProject();
                    inProject.setDocNum(courseNum);
                    inProject.setProjectId(changeOutProject.getCourseProjectId());
                    CardChangeInProject changeInProject = ssmCardChangeInProjectService.selectOne(inProject);
                    List<AchiCommEntity> achiCommList =new ArrayList<>();
                    achiCommList.addAll(this.getAchiCommListKJ(changeInProject,cardChangeInProject,changeOutProject));
//                    //有欠款查询欠款单
                    for (AchiCommEntity achiCommEntity : achiCommList) {
                        achiCommEntity.setDocId(changeOutProject.getId());
                    }
                    changeOutProject.setEntities(achiCommList);
//                    List<AchiCommEntity> achiCommEntityList = new ArrayList<>();
//                    changeOutProject.setEntities(achiCommEntityList);

                }
                else if(courseNum.startsWith("LC")){
                    String substring = courseNum.substring(courseNum.length() - 11, courseNum.length() - 3);
                    StrBuilder strBuilder = new StrBuilder(substring);
                    Date parse;
                    StrBuilder insert = strBuilder.insert(6, "-").insert(4, "-");
                    try {
                        parse = dateFormat.parse(String.valueOf(insert));
                    } catch (ParseException e) {
                        throw new RuntimeException(e);
                    }
                    CourseListRequest courseListRequest = new CourseListRequest();
                    courseListRequest.setDate(parse);
                    courseListRequest.setDocId(courseNum);
                    courseListRequest.setProjctId(changeOutProject.getCourseProjectId());
                    List<CourseList> courseListList = ssmCourseDao.selectCourseOne(courseListRequest);
                    CourseList courseList = courseListList.get(0);
                    List<AchiCommEntity> achiCommList =new ArrayList<>();
                    achiCommList.addAll(this.getAchiCommList(courseList,cardChangeInProject,changeOutProject));
                    //有欠款查询欠款单
                    changeOutProject.setEntities(achiCommList);

                }
                else {
                    changeOutProject.setEntities(new ArrayList<>());
                }
            }

            courseListResponse.setOutProjects(cardChangeOutProjects);
            BigDecimal cooperationCashCarAchisum=new BigDecimal("0");//合作业绩
            for(CardChangeOutProject cardChangeOutProject1:cardChangeOutProjects){
                BaseProject baseProject = ssmProjectService.selectByPrimaryKey(cardChangeOutProject1.getCourseProjectId());
                //isCooperation 比例brokerage 1是比例 0是固定smokeCommissionWay
                if(baseProject.getIsCooperation()==1){
                    if(baseProject.getSmokeCommissionWay()==1){//合作按比例
                        cooperationCashCarAchisum=cooperationCashCarAchisum.add(baseProject.getBrokerage().divide(BigDecimal.valueOf(100)).multiply(cardChangeOutProject1.getChangeOutMoney()));
                    }else{//合作按固定
                        cooperationCashCarAchisum=cooperationCashCarAchisum.add(baseProject.getBrokerage());
                    }
                }
            }
            cardChangeInProject.setChangeOutMoney(cardChangeInProject.getChangeOutMoney().subtract(cooperationCashCarAchisum));

            //设置业务人员列表
            List<AchiCommEntity> entities = this.getAchiCommListByJz(cardChangeInProject);
            courseListResponse.setEntities(entities);
            for (AchiCommEntity entity : entities) {
                entity.setDocId(cardChangeInProject.getId());
                BaseProject baseProject = new BaseProject();
                baseProject.setId(Long.valueOf(entity.getProjectId()));
                BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                entity.setProjectId(baseProject1.getProjectNum());
            }
            listResponses.add(courseListResponse);
        }
        return listResponses;
    }

    public List<AchiCommEntity> getAchiCommList(RepayTradeList repayTradeList,CardChangeInProject cardChangeInProject){
//        repayTradeList.setRepayMoney(repayTradeList.getRepayMoney().negate());
//        repayTradeList.setPayMoney(repayTradeList.getPayMoney().negate());
//        repayTradeList.setAchievementAmount(repayTradeList.getAchievementAmount().negate());
//        repayTradeList.setCommissionAmount(repayTradeList.getCommissionAmount().negate());
//        repayTradeList.setCardAchievementAmount(repayTradeList.getCardAchievementAmount().negate());
//        repayTradeList.setCardCommissionAmount(repayTradeList.getCardCommissionAmount().negate());
        //疗程欠款单，充值开卡添加提成
        BigDecimal coursDebteRecharge = BigDecimal.valueOf(0);
        BigDecimal coursDebteRechargechia = BigDecimal.valueOf(0);

        //疗程欠款单，疗程付款扣或添提成
        BigDecimal courseDebteCourse = BigDecimal.valueOf(0);

        //卡付还款的总金额
        BigDecimal cardTotalMoney=BigDecimal.valueOf(0);
        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");

        RepayAccountList repayAccountList = new RepayAccountList();
        repayAccountList.setRepayTradeId(repayTradeList.getId());

        RepayAccountList repayAccountList1 = new RepayAccountList();
        repayAccountList1.setRepayTradeId(repayTradeList.getId());
        List<RepayAccountList> select1 = ssmRepayAccountListService.select(repayAccountList1);
         if(repayTradeList.getDocType().equals("card_use") || repayTradeList.getDocType().equals("card_change")){
            for (RepayAccountList accountList : select1) {
                cardTotalMoney=cardTotalMoney.add(accountList.getPayMoney());
                if(accountList.getAccountType()==0){
                    //充值卡
                    DebtList debtList = new DebtList();
                    debtList.setId(repayTradeList.getDebtId());
                    DebtList debtList1 = ssmDebtService.selectByPrimaryKey(debtList.getId());
                    CourseAccount courseAccount = new CourseAccount();
                    courseAccount.setId(debtList1.getAccountId());
                    CourseAccount courseAccount1 = ssmCourseAccountService.selectByPrimaryKey(courseAccount.getId());
                    BaseProject baseProject = new BaseProject();
                    baseProject.setId(courseAccount1.getCourseProjectId());
                    BaseProject baseProject1 = ssmProjectService.selectByPrimaryKey(baseProject.getId());
                    baseProject1.setBrokerage(baseProject1.getBrokerage().negate());
                    BigDecimal cardSalesAchievement = baseProject1.getCardSalesAchievement();
                    BigDecimal cardSalesCommission = baseProject1.getCardSalesCommission();
                    if(cardSalesAchievement.compareTo(BigDecimal.valueOf(1))==1){
                        coursDebteRechargechia = coursDebteRechargechia.add(cardSalesAchievement);
                        //固定
                        if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                            coursDebteRecharge=coursDebteRecharge.add(cardSalesCommission);
                        }else{//比例
                            coursDebteRecharge=coursDebteRecharge.add(cardSalesCommission.multiply(cardSalesAchievement));
                        }
                    }else{//比例
                        BigDecimal multiply = cardSalesAchievement.multiply(accountList.getPayMoney());
                        coursDebteRechargechia = coursDebteRechargechia.add(multiply);
                        if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                            coursDebteRecharge=coursDebteRecharge.add(cardSalesCommission);
                        }else{//比例
                            coursDebteRecharge=coursDebteRecharge.add(cardSalesCommission.multiply(multiply));
                        }
                    }
                }else{
                    BigDecimal chia = BigDecimal.valueOf(0);
                    BigDecimal comm = BigDecimal.valueOf(0);
                    BigDecimal chiaout = BigDecimal.valueOf(0);
                    BigDecimal commout = BigDecimal.valueOf(0);
                    //疗程卡
                    DebtList debtList = new DebtList();
                    debtList.setId(repayTradeList.getDebtId());
                    DebtList debtList1 = ssmDebtService.selectByPrimaryKey(debtList.getId());
                    CourseAccount courseAccount = new CourseAccount();
                    courseAccount.setId(debtList1.getAccountId());
                    CourseAccount courseAccount1 = ssmCourseAccountService.selectByPrimaryKey(courseAccount.getId());
                    BaseProject baseProject = new BaseProject();
                    baseProject.setId(courseAccount1.getCourseProjectId());
                    BaseProject baseProject1 = ssmProjectService.selectByPrimaryKey(baseProject.getId());
                    BigDecimal cardSalesAchievement = baseProject1.getCardSalesAchievement();
                    BigDecimal cardSalesCommission = baseProject1.getCardSalesCommission();
                    if(cardSalesAchievement.compareTo(BigDecimal.valueOf(1))==1){
                        //固定
                        if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                            comm=comm.add(cardSalesCommission);
                        }else{//比例
                            comm=comm.add(cardSalesCommission.multiply(cardSalesAchievement));
                        }
                    }else{//比例
                        BigDecimal multiply = cardSalesAchievement.multiply(accountList.getPayMoney());
                        if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                            comm=comm.add(cardSalesCommission);
                        }else{//比例
                            comm=comm.add(cardSalesCommission.multiply(multiply));
                        }
                    }
                    CourseAccount courseAccount3 = new CourseAccount();
                    courseAccount3.setId(accountList.getAccountId());
                    courseAccount3 = ssmCourseAccountService.selectByPrimaryKey(courseAccount3.getId());
                    BaseProject baseProject3 = new BaseProject();
                    baseProject3.setId(courseAccount3.getCourseProjectId());
                    baseProject3 = ssmProjectService.selectByPrimaryKey(baseProject3.getId());
                    cardSalesAchievement = baseProject3.getCardSalesAchievement();
                    cardSalesCommission = baseProject3.getCardSalesCommission();
                    if(cardSalesAchievement.compareTo(BigDecimal.valueOf(1))==1){
                        //固定
                        if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                            commout=commout.add(cardSalesCommission);
                        }else{//比例
                            commout=commout.add(cardSalesCommission.multiply(cardSalesAchievement));
                        }
                    }else{//比例
                        BigDecimal multiply = cardSalesAchievement.multiply(accountList.getPayMoney());
                        if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                            commout=commout.add(cardSalesCommission);
                        }else{//比例
                            commout=commout.add(cardSalesCommission.multiply(multiply));
                        }
                    }
                    //本条疗程的提点
                    BigDecimal bigDecimals = BigDecimal.valueOf(0);
                    if(commout.compareTo(comm)==1){ //扣
                        bigDecimals= commout.subtract(comm);
                        courseDebteCourse=courseDebteCourse.subtract(bigDecimals);
                    }else if(commout.compareTo(comm)==-1){ //加
                        bigDecimals= comm.subtract(commout);
                        courseDebteCourse=courseDebteCourse.add(bigDecimals);
                    }
                }
            }
//            repayTradeList.setCommissionAmount(repayTradeList.getCommissionAmount());
//            repayTradeList.setCardAchievementAmount(repayTradeList.getCardAchievementAmount());
            repayTradeList.setCardCommissionAmount(repayTradeList.getCardCommissionAmount().add(coursDebteRecharge).add(courseDebteCourse));
            //之前的repayTradeList.setPayMoney(repayTradeList.getPayMoney().add(cardTotalMoney));
            repayTradeList.setPayMoney(repayTradeList.getPayMoney());
             BaseProject baseoutProject = ssmProjectService.selectByPrimaryKey(repayTradeList.getTradeId());
             BaseProject baseInProject = ssmProjectService.selectByPrimaryKey(cardChangeInProject.getProjectId());
             BigDecimal cashComm = BigDecimal.valueOf(0);
             BigDecimal cardComm = BigDecimal.valueOf(0);
             //得到疗程合作方抽佣比率
             BigDecimal outBroker = BigDecimal.valueOf(0);
             if(baseoutProject.getIsCooperation()!=null && baseoutProject.getIsCooperation()==1){
                 if(baseoutProject.getSmokeCommissionWay()!=null && baseoutProject.getSmokeCommissionWay()==0){
                     outBroker = baseoutProject.getBrokerage().divide(baseoutProject.getPrice());
                 }
                 if(baseoutProject.getSmokeCommissionWay()!=null && baseoutProject.getSmokeCommissionWay()==1){
                     outBroker = baseoutProject.getBrokerage().divide(BigDecimal.valueOf(100));
                 }
             }
             //计算扣减后的现付提成
             repayTradeList.setNewCashCommissionAmount(repayTradeList.getRepayMoney().multiply(BigDecimal.valueOf(1).subtract(outBroker)).multiply(repayTradeList.getSalesCommission()));
             //计算扣减后的卡付提成
             repayTradeList.setNewCardCommissionAmount(BigDecimal.valueOf(0));
             if(baseInProject.getSalesCommission().compareTo(baseoutProject.getSalesCommission())==-1){
                 //如果转入现付提成比率小于转出的现付提成比率，则进行扣减提成
                 repayTradeList.setCommissionAmount(repayTradeList.getRepayMoney()
                                 //得到扣减合作方的现付总和
                                 .multiply(BigDecimal.valueOf(1).subtract((outBroker).multiply(repayTradeList.getRepayMoney())))
                                 //得到需要扣减的提成
                                 .multiply(baseoutProject.getSalesCommission().subtract(baseInProject.getSalesCommission())));
                 repayTradeList.setCommissionAmount(repayTradeList.getCommissionAmount().negate());
             }else {
                 repayTradeList.setCommissionAmount(BigDecimal.valueOf(0));
             }
             //计算需要扣减的卡付提成
             repayTradeList.setCardCommissionAmount(BigDecimal.valueOf(0));
            if (null != repayTradeList.getSaleOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(repayTradeList.getPayMoney());
                achiCommEntity.setMemberNum(String.valueOf(repayTradeList.getMemberId()));
                achiCommEntity.setMemberName(repayTradeList.getMemberName());
                //achiCommEntity.setProjectId(String.valueOf(repayTradeList.get()));
                achiCommEntity.setDocNum(repayTradeList.getRepayNum());
                achiCommEntity.setDocType(repayTradeList.getDocType());
                achiCommEntity.setType(Constant.doc_type_repay);
                achiCommEntity.setDocDate(repayTradeList.getRepayDate());
                achiCommEntity.setTradeName(repayTradeList.getTradeName());
                achiCommEntity.setBrandNumber(repayTradeList.getSaleOneNumber());
                achiCommEntity.setSaleStaffId(repayTradeList.getSaleOneStaffId());
                achiCommEntity.setSaleStaffName(repayTradeList.getSaleOneStaffName());
                achiCommEntity.setSaleIdentityCard(repayTradeList.getSaleOneIdentity());
                achiCommEntity.setSaleRatio(repayTradeList.getSaleOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD))));
//                achiCommEntity.setCashAchi(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
                achiCommEntity.setCashComm(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
//                achiCommEntity.setCardAchi(BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
//                achiCommEntity.setCardComm(BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }

                //计算卡付
                achiCommEntity.setTotalPerformance(achiCommEntity.getCashAchi().add(achiCommEntity.getCardAchi()));
                achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                achiCommEntity.setNTMoney(BigDecimalUtils.multiply(cardTotalMoney,BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));

                entities.add(achiCommEntity);
            }
            if (null != repayTradeList.getSaleTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(repayTradeList.getPayMoney());
                achiCommEntity.setMemberNum(String.valueOf(repayTradeList.getMemberId()));
                achiCommEntity.setMemberName(repayTradeList.getMemberName());
                achiCommEntity.setDocNum(repayTradeList.getRepayNum());
                achiCommEntity.setDocType(repayTradeList.getDocType());
                achiCommEntity.setType(Constant.doc_type_repay);
                achiCommEntity.setDocDate(repayTradeList.getRepayDate());
                achiCommEntity.setTradeName(repayTradeList.getTradeName());
                achiCommEntity.setBrandNumber(repayTradeList.getSaleTwoNumber());
                achiCommEntity.setSaleStaffId(repayTradeList.getSaleTwoStaffId());
                achiCommEntity.setSaleStaffName(repayTradeList.getSaleTwoStaffName());
                achiCommEntity.setSaleIdentityCard(repayTradeList.getSaleTwoIdentity());
                achiCommEntity.setSaleRatio(repayTradeList.getSaleTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)),
//                        BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD))));
//                achiCommEntity.setCashAchi(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));
                achiCommEntity.setCashComm(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));
//                achiCommEntity.setCardAchi(BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));
//                achiCommEntity.setCardComm(BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(achiCommEntity.getCashAchi().add(achiCommEntity.getCardAchi()));
                achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                achiCommEntity.setNTMoney(BigDecimalUtils.multiply(cardTotalMoney,BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));

                entities.add(achiCommEntity);
            }
            if (null != repayTradeList.getSaleThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(repayTradeList.getPayMoney());
                achiCommEntity.setMemberNum(String.valueOf(repayTradeList.getMemberId()));
                achiCommEntity.setMemberName(repayTradeList.getMemberName());
                achiCommEntity.setDocNum(repayTradeList.getRepayNum());
                achiCommEntity.setDocType(repayTradeList.getDocType());
                achiCommEntity.setType(Constant.doc_type_repay);
                achiCommEntity.setDocDate(repayTradeList.getRepayDate());
                achiCommEntity.setTradeName(repayTradeList.getTradeName());
                achiCommEntity.setBrandNumber(repayTradeList.getSaleThreeNumber());
                achiCommEntity.setSaleStaffId(repayTradeList.getSaleThreeStaffId());
                achiCommEntity.setSaleStaffName(repayTradeList.getSaleThreeStaffName());
                achiCommEntity.setSaleIdentityCard(repayTradeList.getSaleThreeIdentity());
                achiCommEntity.setSaleRatio(repayTradeList.getSaleThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)),
//                        BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD))));
//                achiCommEntity.setCashAchi(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));
                achiCommEntity.setCashComm(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));
//                achiCommEntity.setCardAchi(BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));
//                achiCommEntity.setCardComm(BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(achiCommEntity.getCashAchi().add(achiCommEntity.getCardAchi()));
                achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                achiCommEntity.setNTMoney(BigDecimalUtils.multiply(cardTotalMoney,BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));

                entities.add(achiCommEntity);
            }
            if (null != repayTradeList.getSaleFourStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(repayTradeList.getPayMoney());
                achiCommEntity.setMemberNum(String.valueOf(repayTradeList.getMemberId()));
                achiCommEntity.setMemberName(repayTradeList.getMemberName());
                achiCommEntity.setDocNum(repayTradeList.getRepayNum());
                achiCommEntity.setDocType(repayTradeList.getDocType());
                achiCommEntity.setType(Constant.doc_type_repay);
                achiCommEntity.setDocDate(repayTradeList.getRepayDate());
                achiCommEntity.setTradeName(repayTradeList.getTradeName());
                achiCommEntity.setBrandNumber(repayTradeList.getSaleFourNumber());
                achiCommEntity.setSaleStaffId(repayTradeList.getSaleFourStaffId());
                achiCommEntity.setSaleStaffName(repayTradeList.getSaleFourStaffName());
                achiCommEntity.setSaleIdentityCard(repayTradeList.getSaleFourIdentity());
                achiCommEntity.setSaleRatio(repayTradeList.getSaleFourRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)),
//                        BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD))));
//                achiCommEntity.setCashAchi(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));
                achiCommEntity.setCashComm(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));
//                achiCommEntity.setCardAchi(BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));
//                achiCommEntity.setCardComm(BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(achiCommEntity.getCashAchi().add(achiCommEntity.getCardAchi()));
                achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                achiCommEntity.setNTMoney(BigDecimalUtils.multiply(cardTotalMoney,BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));

                entities.add(achiCommEntity);
            }
        }
         else {//项目促销
            for (RepayAccountList accountList : select1) {
                cardTotalMoney=cardTotalMoney.add(accountList.getPayMoney());
                if(accountList.getAccountType()==0){
                    //充值卡
                    DocPromotion docPromotion = new DocPromotion();
                    docPromotion.setId(repayTradeList.getDocId());
                    DocPromotion docPromotion1 = ssmDocPromotionService.selectOne(docPromotion);
                    BigDecimal cardSalesCommission = docPromotion1.getCardSalesCommission();
                    if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                        coursDebteRecharge=coursDebteRecharge.add(cardSalesCommission);
                    }else{//比例
                        coursDebteRecharge=coursDebteRecharge.add(cardSalesCommission.multiply(accountList.getPayMoney()));
                    }
                }else{
                    BigDecimal chia = BigDecimal.valueOf(0);
                    BigDecimal comm = BigDecimal.valueOf(0);
                    BigDecimal chiaout = BigDecimal.valueOf(0);
                    BigDecimal commout = BigDecimal.valueOf(0);
                    //疗程卡
                    DebtList debtList = new DebtList();
                    debtList.setId(repayTradeList.getDebtId());
                    DebtList debtList1 = ssmDebtService.selectByPrimaryKey(debtList.getId());

                    List<DocPromotionProject> docPromotionProjects=new ArrayList<>();
                    DocPromotion docPromotion=ssmDocPromotionService.selectByPrimaryKey(debtList1.getDocId());
                    DocPromotionProject docPromotionProject=new DocPromotionProject();
                    docPromotionProject.setDocNum(docPromotion.getDocNum());
                    docPromotionProjects=ssmDocPromotionProjectService.select(docPromotionProject);
                    if(docPromotionProjects.size()>0){
                        for(DocPromotionProject docPromotionProject1:docPromotionProjects){
                            BaseProject baseProject1 = ssmProjectService.selectByPrimaryKey(docPromotionProject1.getProjectId());
                            BigDecimal cardSalesAchievement = baseProject1.getCardSalesAchievement();
                            BigDecimal cardSalesCommission = baseProject1.getCardSalesCommission();
                            if(cardSalesAchievement.compareTo(BigDecimal.valueOf(1))==1){
                                //固定
                                if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                                    comm=comm.add(cardSalesCommission);
                                }else{//比例
                                    comm=comm.add(cardSalesCommission.multiply(cardSalesAchievement));
                                }
                            }else{//比例
                                BigDecimal multiply = cardSalesAchievement.multiply(accountList.getPayMoney());
                                if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                                    comm=comm.add(cardSalesCommission);
                                }else{//比例
                                    comm=comm.add(cardSalesCommission.multiply(multiply));
                                }
                            }
                        }
                    }

                    /*CourseAccount courseAccount = new CourseAccount();
                    courseAccount.setId(debtList1.getAccountId());
                    CourseAccount courseAccount1 = ssmCourseAccountService.selectByPrimaryKey(courseAccount.getId());
                    BaseProject baseProject = new BaseProject();
                    baseProject.setId(courseAccount1.getCourseProjectId());
                    BaseProject baseProject1 = ssmProjectService.selectByPrimaryKey(baseProject.getId());
                    BigDecimal cardSalesAchievement = baseProject1.getCardSalesAchievement();
                    BigDecimal cardSalesCommission = baseProject1.getCardSalesCommission();
                    if(cardSalesAchievement.compareTo(BigDecimal.valueOf(1))==1){
                        //固定
                        if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                            comm=comm.add(cardSalesCommission);
                        }else{//比例
                            comm=comm.add(cardSalesCommission.multiply(cardSalesAchievement));
                        }
                    }else{//比例
                        BigDecimal multiply = cardSalesAchievement.multiply(accountList.getPayMoney());
                        if(cardSalesCommission.compareTo(BigDecimal.valueOf(1))==1){ //固定
                            comm=comm.add(cardSalesCommission);
                        }else{//比例
                            comm=comm.add(cardSalesCommission.multiply(multiply));
                        }
                    }*/

                    BigDecimal cardSalesCommission1 = docPromotion.getCardSalesCommission();
                    if(cardSalesCommission1.compareTo(BigDecimal.valueOf(1))==1){ //固定
                        commout=commout.add(cardSalesCommission1);
                    }else{//比例
                        commout=commout.add(cardSalesCommission1.multiply(accountList.getPayMoney()));
                    }
                    //本条疗程的提点
                    BigDecimal bigDecimals = BigDecimal.valueOf(0);
                    if(commout.compareTo(comm)==1){ //扣
                        bigDecimals= commout.subtract(comm);
                        courseDebteCourse=courseDebteCourse.subtract(bigDecimals);
                    }else if(commout.compareTo(comm)==-1){ //加
                        bigDecimals= comm.subtract(commout);
                        courseDebteCourse=courseDebteCourse.add(bigDecimals);
                    }
                }
            }
            repayTradeList.setCardCommissionAmount(repayTradeList.getCardCommissionAmount().add(coursDebteRecharge).add(courseDebteCourse));

            //之前的repayTradeList.setPayMoney(repayTradeList.getPayMoney().add(cardTotalMoney));
            repayTradeList.setPayMoney(repayTradeList.getPayMoney());
            if (null != repayTradeList.getSaleOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(repayTradeList.getPayMoney());
                achiCommEntity.setMemberNum(String.valueOf(repayTradeList.getMemberId()));
                achiCommEntity.setMemberName(repayTradeList.getMemberName());
                //achiCommEntity.setProjectId(String.valueOf(repayTradeList.get()));
                achiCommEntity.setDocNum(repayTradeList.getRepayNum());
                achiCommEntity.setDocType(repayTradeList.getDocType());
                achiCommEntity.setType(Constant.doc_type_repay);
                achiCommEntity.setDocDate(repayTradeList.getRepayDate());
                achiCommEntity.setTradeName(repayTradeList.getTradeName());
                achiCommEntity.setBrandNumber(repayTradeList.getSaleOneNumber());
                achiCommEntity.setSaleStaffId(repayTradeList.getSaleOneStaffId());
                achiCommEntity.setSaleStaffName(repayTradeList.getSaleOneStaffName());
                achiCommEntity.setSaleIdentityCard(repayTradeList.getSaleOneIdentity());
                achiCommEntity.setSaleRatio(repayTradeList.getSaleOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD))));
                achiCommEntity.setCashAchi(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
                achiCommEntity.setCashComm(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
                achiCommEntity.setCardAchi(BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
                achiCommEntity.setCardComm(BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                //计算卡付
                achiCommEntity.setNTMoney(BigDecimalUtils.multiply(cardTotalMoney,BigDecimalUtils.div(repayTradeList.getSaleOneRatio(),hundredBD)));
                achiCommEntity.setTotalPerformance(achiCommEntity.getCashAchi().add(achiCommEntity.getCardAchi()));
                achiCommEntity.setCooperationAchi(repayTradeList.getPayMoney().subtract(achiCommEntity.getTotalPerformance()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);
            }
            if (null != repayTradeList.getSaleTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(repayTradeList.getPayMoney());
                achiCommEntity.setMemberNum(String.valueOf(repayTradeList.getMemberId()));
                achiCommEntity.setMemberName(repayTradeList.getMemberName());
                achiCommEntity.setDocNum(repayTradeList.getRepayNum());
                achiCommEntity.setDocType(repayTradeList.getDocType());
                achiCommEntity.setType(Constant.doc_type_repay);
                achiCommEntity.setDocDate(repayTradeList.getRepayDate());
                achiCommEntity.setTradeName(repayTradeList.getTradeName());
                achiCommEntity.setBrandNumber(repayTradeList.getSaleTwoNumber());
                achiCommEntity.setSaleStaffId(repayTradeList.getSaleTwoStaffId());
                achiCommEntity.setSaleStaffName(repayTradeList.getSaleTwoStaffName());
                achiCommEntity.setSaleIdentityCard(repayTradeList.getSaleTwoIdentity());
                achiCommEntity.setSaleRatio(repayTradeList.getSaleTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD))));
                achiCommEntity.setCashAchi(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));
                achiCommEntity.setCashComm(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));
                achiCommEntity.setCardAchi(BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));
                achiCommEntity.setCardComm(BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(achiCommEntity.getCashAchi().add(achiCommEntity.getCardAchi()));
                achiCommEntity.setCooperationAchi(repayTradeList.getPayMoney().subtract(achiCommEntity.getTotalPerformance()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                achiCommEntity.setNTMoney(BigDecimalUtils.multiply(cardTotalMoney,BigDecimalUtils.div(repayTradeList.getSaleTwoRatio(),hundredBD)));

                entities.add(achiCommEntity);
            }
            if (null != repayTradeList.getSaleThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(repayTradeList.getPayMoney());
                achiCommEntity.setMemberNum(String.valueOf(repayTradeList.getMemberId()));
                achiCommEntity.setMemberName(repayTradeList.getMemberName());
                achiCommEntity.setDocNum(repayTradeList.getRepayNum());
                achiCommEntity.setDocType(repayTradeList.getDocType());
                achiCommEntity.setType(Constant.doc_type_repay);
                achiCommEntity.setDocDate(repayTradeList.getRepayDate());
                achiCommEntity.setTradeName(repayTradeList.getTradeName());
                achiCommEntity.setBrandNumber(repayTradeList.getSaleThreeNumber());
                achiCommEntity.setSaleStaffId(repayTradeList.getSaleThreeStaffId());
                achiCommEntity.setSaleStaffName(repayTradeList.getSaleThreeStaffName());
                achiCommEntity.setSaleIdentityCard(repayTradeList.getSaleThreeIdentity());
                achiCommEntity.setSaleRatio(repayTradeList.getSaleThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD))));
                achiCommEntity.setCashAchi(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));
                achiCommEntity.setCashComm(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));
                achiCommEntity.setCardAchi(BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));
                achiCommEntity.setCardComm(BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(achiCommEntity.getCashAchi().add(achiCommEntity.getCardAchi()));
                achiCommEntity.setCooperationAchi(repayTradeList.getPayMoney().subtract(achiCommEntity.getTotalPerformance()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                achiCommEntity.setNTMoney(BigDecimalUtils.multiply(cardTotalMoney,BigDecimalUtils.div(repayTradeList.getSaleThreeRatio(),hundredBD)));

                entities.add(achiCommEntity);
            }
            if (null != repayTradeList.getSaleFourStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(repayTradeList.getPayMoney());
                achiCommEntity.setMemberNum(String.valueOf(repayTradeList.getMemberId()));
                achiCommEntity.setMemberName(repayTradeList.getMemberName());
                achiCommEntity.setDocNum(repayTradeList.getRepayNum());
                achiCommEntity.setDocType(repayTradeList.getDocType());
                achiCommEntity.setType(Constant.doc_type_repay);
                achiCommEntity.setDocDate(repayTradeList.getRepayDate());
                achiCommEntity.setTradeName(repayTradeList.getTradeName());
                achiCommEntity.setBrandNumber(repayTradeList.getSaleFourNumber());
                achiCommEntity.setSaleStaffId(repayTradeList.getSaleFourStaffId());
                achiCommEntity.setSaleStaffName(repayTradeList.getSaleFourStaffName());
                achiCommEntity.setSaleIdentityCard(repayTradeList.getSaleFourIdentity());
                achiCommEntity.setSaleRatio(repayTradeList.getSaleFourRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)),
                        BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD))));
                achiCommEntity.setCashAchi(BigDecimalUtils.multiply(repayTradeList.getAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));
                achiCommEntity.setCashComm(BigDecimalUtils.multiply(repayTradeList.getCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));
                achiCommEntity.setCardAchi(BigDecimalUtils.multiply(repayTradeList.getCardAchievementAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));
                achiCommEntity.setCardComm(BigDecimalUtils.multiply(repayTradeList.getCardCommissionAmount(),BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(achiCommEntity.getCashAchi().add(achiCommEntity.getCardAchi()));
                achiCommEntity.setCooperationAchi(repayTradeList.getPayMoney().subtract(achiCommEntity.getTotalPerformance()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                achiCommEntity.setNTMoney(BigDecimalUtils.multiply(cardTotalMoney,BigDecimalUtils.div(repayTradeList.getSaleFourRatio(),hundredBD)));

                entities.add(achiCommEntity);
            }
        }

        return entities;
    }


    public List<AchiCommEntity> getAchiCommList(CourseList cardChangeOutProject ,CardChangeInProject cardChangeInProject,CardChangeOutProject courseList) {
        List<AchiCommEntity> entities = new ArrayList<>();
        BaseProject baseoutProject = ssmProjectService.selectByPrimaryKey(cardChangeOutProject.getProjctId());
        BaseProject baseInProject = ssmProjectService.selectByPrimaryKey(cardChangeInProject.getProjectId());
        BigDecimal cashComm = BigDecimal.valueOf(0);
        BigDecimal cardComm = BigDecimal.valueOf(0);
        //得到疗程合作方抽佣比率
        BigDecimal outBroker = BigDecimal.valueOf(0);
        if(baseoutProject.getIsCooperation()!=null && baseoutProject.getIsCooperation()==1){
            if(baseoutProject.getSmokeCommissionWay()!=null && baseoutProject.getSmokeCommissionWay()==0){
                outBroker = baseoutProject.getBrokerage().divide(baseoutProject.getPrice().compareTo(BigDecimal.ZERO)==0?baseoutProject.getPriceMember():baseoutProject.getPrice(),10,BigDecimal.ROUND_HALF_UP);
            }
            if(baseoutProject.getSmokeCommissionWay()!=null && baseoutProject.getSmokeCommissionWay()==1){
                outBroker = baseoutProject.getBrokerage().divide(BigDecimal.valueOf(100));
            }
        }

        //计算扣减后的现付提成
        courseList.setCommissionAmount(cardChangeOutProject.getCollectionCashAmount().multiply(BigDecimal.valueOf(1).subtract(outBroker)).multiply(courseList.getSalesCommission()));
        //计算扣减后的卡付提成
        courseList.setCardCommissionAmount(cardChangeOutProject.getCollectionRechargeAmount().multiply(BigDecimal.valueOf(1).subtract(outBroker)).multiply(courseList.getCardSalesCommission()));
        if(baseInProject.getSalesCommission().compareTo(baseoutProject.getSalesCommission())==-1){
            //如果转入现付提成比率小于转出的现付提成比率，则进行扣减提成
            courseList.setCommissionAmount(
                    //得到现付总额
                    courseList.getChangeOutMoney().multiply(cardChangeOutProject.getCollectionCashAmount().divide(cardChangeOutProject.getAmount(),10,BigDecimal.ROUND_HALF_UP))
                            //得到扣减合作方的现付总和
                            .multiply(BigDecimal.valueOf(1).subtract(outBroker))
                            //得到需要扣减的提成
                    .multiply(baseoutProject.getSalesCommission().subtract(baseInProject.getSalesCommission())));
            courseList.setCommissionAmount(courseList.getCommissionAmount().negate());
            cardChangeInProject.setChangeOutMoney(cardChangeInProject.getChangeOutMoney().add(//得到现付总额
                    courseList.getChangeOutMoney().multiply(cardChangeOutProject.getCollectionCashAmount().divide(cardChangeOutProject.getAmount(),10,BigDecimal.ROUND_HALF_UP))
                            //得到扣减合作方的现付总和
                            .multiply(BigDecimal.valueOf(1).subtract(outBroker))));
        }else {
            courseList.setCommissionAmount(BigDecimal.valueOf(0));
            cardChangeInProject.setChangeOutMoney(cardChangeInProject.getChangeOutMoney().add(BigDecimal.valueOf(0)));
        }
        //计算需要扣减的卡付提成
        if(baseInProject.getCardSalesCommission().compareTo(baseoutProject.getCardSalesCommission())==-1){
            courseList.setCardCommissionAmount(courseList.getCardCommissionAmount().subtract(
                    //得到现付总额
                            courseList.getChangeOutMoney().multiply(cardChangeOutProject.getCollectionRechargeAmount()).divide(cardChangeOutProject.getAmount(),10,BigDecimal.ROUND_HALF_UP))
                            //得到扣减合作方的现付总和
                            .multiply(BigDecimal.valueOf(1).subtract(outBroker))
                            //得到需要扣减的提成
                            .multiply(baseoutProject.getCardSalesCommission().subtract(baseInProject.getCardSalesCommission())));
            courseList.setCardCommissionAmount(courseList.getCardCommissionAmount().negate());
            cardChangeInProject.setChangeOutMoney(cardChangeInProject.getChangeOutMoney().add(//得到现付总额
                            courseList.getChangeOutMoney().multiply(cardChangeOutProject.getCollectionRechargeAmount()).divide(cardChangeOutProject.getAmount(),10,BigDecimal.ROUND_HALF_UP))
                    //得到扣减合作方的现付总和
                    .multiply(BigDecimal.valueOf(1).subtract(outBroker)));
        }else {
            courseList.setCardCommissionAmount(BigDecimal.valueOf(0));
            cardChangeInProject.setChangeOutMoney(cardChangeInProject.getChangeOutMoney().add(BigDecimal.valueOf(0)));

        }
        //需要扣减的提成进行取反
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");
        //转出扣提成
        if (null != courseList.getSaleOneStaffId()) {
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setDocId(courseList.getId());
            achiCommEntity.setMoney(cardChangeOutProject.getCourseReatmentAmount());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(cardChangeOutProject.getProjctId()));
            achiCommEntity.setDocNum(cardChangeOutProject.getCourseReatmentNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(cardChangeOutProject.getDate());
            achiCommEntity.setTradeName(cardChangeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleOneNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleOneStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleOneStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleOneIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleOneRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils
//                    .add(BigDecimalUtils
//                                    .multiply(courseList.getAchievementAmount().setScale(10,BigDecimal.ROUND_HALF_UP),
//                                            courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
//                            BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),  courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),  courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(courseList.getCommissionAmount(),  courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),  courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardComm(BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));

//            if (baseoutProject.getIsCooperation() != null && baseoutProject.getIsCooperation() == 1 && baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 0) {
////                achiCommEntity.setCooperationAchi(baseoutProject.getBrokerage().divide(new BigDecimal("100")).multiply(courseList.getSaleOneRatio()));
//                achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
//            } else if (baseoutProject.getIsCooperation() != null && baseoutProject.getIsCooperation() == 1 && baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 1) {
////                achiCommEntity.setCooperationAchi((courseList.getAchievementAmount().add(courseList.getCardAchievementAmount()))
////                        .multiply( courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))
////                        .multiply(baseoutProject.getBrokerage().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            }
            achiCommEntity.setCashCoopAchi(BigDecimal.valueOf(0));

            if (null == achiCommEntity.getCashAchi()) {
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardAchi()) {
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCashComm()) {
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardComm()) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(), achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(), achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleTwoStaffId()) {
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setDocId(courseList.getId());
            achiCommEntity.setMoney(cardChangeOutProject.getCourseReatmentAmount());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(cardChangeOutProject.getProjctId()));
            achiCommEntity.setDocNum(cardChangeOutProject.getCourseReatmentNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(cardChangeOutProject.getDate());
            achiCommEntity.setTradeName(cardChangeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleTwoNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleTwoStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleTwoStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleTwoIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleTwoRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount().setScale(10,BigDecimal.ROUND_HALF_UP), courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardComm(BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));

//            if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 0) {
////                achiCommEntity.setCooperationAchi(baseoutProject.getBrokerage().divide(new BigDecimal("100")).multiply(courseList.getSaleTwoRatio()));
//                achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
//            } else if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 1) {
////                achiCommEntity.setCooperationAchi((courseList.getAchievementAmount().add(courseList.getCardAchievementAmount()))
////                        .multiply(courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))
////                        .multiply(baseoutProject.getBrokerage().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            }
            achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));

            if (null == achiCommEntity.getCashAchi()) {
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardAchi()) {
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCashComm()) {
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardComm()) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(), achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(), achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleThreeStaffId()) {
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setDocId(courseList.getId());
            achiCommEntity.setMoney(cardChangeOutProject.getCourseReatmentAmount());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(cardChangeOutProject.getProjctId()));
            achiCommEntity.setDocNum(cardChangeOutProject.getCourseReatmentNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(cardChangeOutProject.getDate());
            achiCommEntity.setTradeName(cardChangeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleThreeNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleThreeStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleThreeStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleThreeIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleThreeRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount().setScale(10,BigDecimal.ROUND_HALF_UP), courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardComm(BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));


//            if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 0) {
//                achiCommEntity.setCooperationAchi(baseoutProject.getBrokerage().divide(new BigDecimal("100")).multiply(courseList.getSaleThreeRatio()));
//            } else if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 1) {
//                achiCommEntity.setCooperationAchi((courseList.getAchievementAmount().add(courseList.getCardAchievementAmount()))
//                        .multiply(courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))
//                        .multiply(baseoutProject.getBrokerage().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            }
            achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
            if (null == achiCommEntity.getCashAchi()) {
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardAchi()) {
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCashComm()) {
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardComm()) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(), achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(), achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFourStaffId()) {
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setDocId(courseList.getId());
            achiCommEntity.setMoney(cardChangeOutProject.getCourseReatmentAmount());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(cardChangeOutProject.getProjctId()));
            achiCommEntity.setDocNum(cardChangeOutProject.getCourseReatmentNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(cardChangeOutProject.getDate());
            achiCommEntity.setTradeName(cardChangeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFourNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFourStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFourStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFourIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFourRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardComm(BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));

//            if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 0) {
//                achiCommEntity.setCooperationAchi(baseoutProject.getBrokerage().divide(new BigDecimal("100")).multiply(courseList.getSaleFourRatio()));
//            } else if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 1) {
//                achiCommEntity.setCooperationAchi((courseList.getAchievementAmount().add(courseList.getCardAchievementAmount()))
//                        .multiply(courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))
//                        .multiply(baseoutProject.getBrokerage().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            }
            achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
            if (null == achiCommEntity.getCashAchi()) {
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardAchi()) {
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCashComm()) {
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardComm()) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(), achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(), achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFiveStaffId()) {
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setDocId(courseList.getId());
            achiCommEntity.setMoney(cardChangeOutProject.getCourseReatmentAmount());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(cardChangeOutProject.getProjctId()));
            achiCommEntity.setDocNum(cardChangeOutProject.getCourseReatmentNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(cardChangeOutProject.getDate());
            achiCommEntity.setTradeName(cardChangeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFiveNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFiveStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFiveStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFiveIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFiveRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardComm(BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));

//            if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 0) {
//                achiCommEntity.setCooperationAchi(baseoutProject.getBrokerage().divide(new BigDecimal("100")).multiply(courseList.getSaleFiveRatio()));
//            } else if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 1) {
//                achiCommEntity.setCooperationAchi((courseList.getAchievementAmount().add(courseList.getCardAchievementAmount()))
//                        .multiply(courseList.getSaleFiveRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))
//                        .multiply(baseoutProject.getBrokerage().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            }
            achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
            if (null == achiCommEntity.getCashAchi()) {
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardAchi()) {
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCashComm()) {
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }


            if (null == achiCommEntity.getCardComm()) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(), achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(), achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleSixStaffId()) {
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setDocId(courseList.getId());
            achiCommEntity.setMoney(cardChangeOutProject.getCourseReatmentAmount());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(cardChangeOutProject.getProjctId()));
            achiCommEntity.setDocNum(cardChangeOutProject.getCourseReatmentNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(cardChangeOutProject.getDate());
            achiCommEntity.setTradeName(cardChangeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleSixNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleSixStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleSixStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleSixIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleSixRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardComm(BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));

//            if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 0) {
//                achiCommEntity.setCooperationAchi(baseoutProject.getBrokerage().divide(new BigDecimal("100")).multiply(courseList.getSaleSixRatio()));
//            } else if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 1) {
//                achiCommEntity.setCooperationAchi((courseList.getAchievementAmount().add(courseList.getCardAchievementAmount()))
//                        .multiply(courseList.getSaleSixRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))
//                        .multiply(baseoutProject.getBrokerage().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            }
            achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
            if (null == achiCommEntity.getCashAchi()) {
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardAchi()) {
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCashComm()) {
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardComm()) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(), achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(), achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleSevenStaffId()) {
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setDocId(courseList.getId());
            achiCommEntity.setMoney(cardChangeOutProject.getCourseReatmentAmount());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(cardChangeOutProject.getProjctId()));
            achiCommEntity.setDocNum(cardChangeOutProject.getCourseReatmentNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(cardChangeOutProject.getDate());
            achiCommEntity.setTradeName(cardChangeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleSevenNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleSevenStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleSevenStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleSevenIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleSevenRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardComm(BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));

//            if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 0) {
//                achiCommEntity.setCooperationAchi(baseoutProject.getBrokerage().divide(new BigDecimal("100")).multiply(courseList.getSaleSevenRatio()));
//            } else if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 1) {
//                achiCommEntity.setCooperationAchi((courseList.getAchievementAmount().add(courseList.getCardAchievementAmount()))
//                        .multiply(courseList.getSaleSevenRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))
//                        .multiply(baseoutProject.getBrokerage().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            }
            achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
            if (null == achiCommEntity.getCashAchi()) {
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardAchi()) {
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCashComm()) {
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardComm()) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(), achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(), achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleEightStaffId() && courseList.getSaleEightStaffId() != 0) {
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setDocId(courseList.getId());
            achiCommEntity.setMoney(cardChangeOutProject.getCourseReatmentAmount());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(cardChangeOutProject.getProjctId()));
            achiCommEntity.setDocNum(cardChangeOutProject.getCourseReatmentNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(cardChangeOutProject.getDate());
            achiCommEntity.setTradeName(cardChangeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleEightNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleEightStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleEightStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleEightIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleEightRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.valueOf(0));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(courseList.getAchievementAmount(), courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(courseList.getCommissionAmount(), courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(courseList.getCardAchievementAmount(), courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setCardComm(BigDecimalUtils.multiply(courseList.getCardCommissionAmount(), courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));

//            if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 0) {
//                achiCommEntity.setCooperationAchi(baseoutProject.getBrokerage().divide(new BigDecimal("100")).multiply(courseList.getSaleEightRatio()));
//            } else if (baseoutProject.getSmokeCommissionWay() != null && baseoutProject.getSmokeCommissionWay() == 1) {
//                achiCommEntity.setCooperationAchi((courseList.getAchievementAmount().add(courseList.getCardAchievementAmount()))
//                        .multiply(courseList.getSaleEightRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP))
//                        .multiply(baseoutProject.getBrokerage().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
//            }
            achiCommEntity.setCooperationAchi(BigDecimal.valueOf(0));
            if (null == achiCommEntity.getCashAchi()) {
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardAchi()) {
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCashComm()) {
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if (null == achiCommEntity.getCardComm()) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(), achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(), achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }

        return entities;
    }


    @Override
    public List<CardChangeInProjectResponse> selectListAbnormal(Long storeId, String date){
        Example example = new Example(CardChangeList.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId",storeId);
        criteria.andLike("docDate", date + "%");
        criteria.andEqualTo("state", 3);
        List<CardChangeList> cardChangeLists = dao.selectByExample(example);
        List<CardChangeInProject> cardChangeInProjects = new ArrayList<>();
        for (CardChangeList cardChangeList : cardChangeLists) {
            if(cardChangeList.getDocNum().startsWith("LCNT")){
                continue;
            }
            Example examples = new Example(CardChangeInProject.class);
            Example.Criteria criterias = examples.createCriteria();
            criterias.andEqualTo("docNum",cardChangeList.getDocNum());
            List<CardChangeInProject> cardChangeInProjectlist = ssmCardChangeInProjectService.selectByExample(examples);
            for (CardChangeInProject cardChangeInProject : cardChangeInProjectlist) {
                cardChangeInProjects.add(cardChangeInProject);
            }
        }
        List<CardChangeInProjectResponse> listResponses = new ArrayList<>();
        for (CardChangeInProject cardChangeInProject :cardChangeInProjects) {
            //总业绩
            BigDecimal totalPerformance = BigDecimal.valueOf(0);
            CardChangeInProjectResponse courseListResponse = new CardChangeInProjectResponse();

            BeanUtils.copyProperties(cardChangeInProject,courseListResponse);
            courseListResponse.setProject(ssmProjectService.selectByPrimaryKey(cardChangeInProject.getProjectId()));
            //设置业务人员列表
            List<AchiCommEntity> entities = this.getAchiCommList(cardChangeInProject);
            for (AchiCommEntity entity : entities) {
                totalPerformance=totalPerformance.add(entity.getCashAchi()
//                        .add(entity.getCardAchi())
                );
            }
            if(totalPerformance.subtract(cardChangeInProject.getChangeInPayMoney()
//                    .add(cardChangeInProject.getChangeOutMoney())
            ).abs().compareTo(new BigDecimal("0.05")) == 1 ){
                courseListResponse.setEntities(entities);
                courseListResponse.setErrorMessage("请检查是否填写员工或者漏填员工，无误则检查项目是否有业绩提成");
                listResponses.add(courseListResponse);
            }
            List<AchiCommEntity> collect = entities.stream().filter(item ->item.getSaleStaffId()!=null && item.getSaleRatio().compareTo(BigDecimal.valueOf(0)) == 0).collect(Collectors.toList());
            if(collect!=null && collect.size()>0){
                courseListResponse.setEntities(entities);
                courseListResponse.setErrorMessage("存在占比为零的员工存在");
                if(!listResponses.contains(courseListResponse)){
                    listResponses.add(courseListResponse);
                }
            }
        }
        return listResponses;
    }

    @Override
    public List<CardChangeInProject> selectListchia(Long storeId, Date startDate,Date endDate){
        Example example = new Example(CardChangeList.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId",storeId);
        criteria.andBetween("docDate",startDate,endDate);
        List<CardChangeList> cardChangeLists = dao.selectByExample(example);
        List<CardChangeInProject> cardChangeInProjects = new ArrayList<>();
        for (CardChangeList cardChangeList : cardChangeLists) {
            Example examples = new Example(CardChangeInProject.class);
            Example.Criteria criterias = examples.createCriteria();
            criterias.andEqualTo("docNum",cardChangeList.getDocNum());
            List<CardChangeInProject> cardChangeInProjectlist = ssmCardChangeInProjectService.selectByExample(examples);
            for (CardChangeInProject cardChangeInProject : cardChangeInProjectlist) {
                cardChangeInProjects.add(cardChangeInProject);
            }
        }


        //ssmCardChangeInProjectService

        return cardChangeInProjects;
    }
    /*
     * 业务员列表设置返回值
     * */
    public List<AchiCommEntity> getAchiCommListKJ(CardChangeInProject changeOutProject,CardChangeInProject cardChangeInProject,CardChangeOutProject courseList ){
        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");
        //得到疗程合作方抽佣比率
        BaseProject baseProject = ssmProjectService.selectByPrimaryKey(changeOutProject.getProjectId());
        BigDecimal cooperationCashAchi=new BigDecimal("0");//合作现付业绩
        //isCooperation 比例brokerage 1是比例 0是固定smokeCommissionWay
        if(baseProject.getIsCooperation()==1){
            if(baseProject.getSmokeCommissionWay()!=null&&baseProject.getSmokeCommissionWay()==1){//合作按比例
//                cooperationCashAchi=baseProject.getBrokerage().multiply(courseList.getChangeInPayMoney());
                cooperationCashAchi=baseProject.getBrokerage().multiply(courseList.getChangeOutMoney());
            }else{//合作按固定
                cooperationCashAchi=baseProject.getBrokerage();
            }
        }
        //判断转出和转入的项目提成的是否有提成差
        //计算扣减后的现付提成
        if(courseList.getSalesCommission().compareTo(cardChangeInProject.getSalesCommission())==1){
            courseList.setSalesCommission(courseList.getSalesCommission().subtract(cardChangeInProject.getSalesCommission()));
        }else {
            courseList.setSalesCommission(BigDecimal.ZERO);
        }


//        courseList.setChangeInPayMoney(courseList.getChangeInPayMoney().subtract(cooperationCashAchi));
        changeOutProject.setChangeInPayMoney(courseList.getChangeOutMoney().subtract(cooperationCashAchi));
        changeOutProject.setChangeInPayMoney(changeOutProject.getChangeInPayMoney().negate());
        courseList.setChangeOutMoney(courseList.getChangeOutMoney().negate().add(BigDecimal.valueOf(0)));
        courseList.setAchievementAmount(changeOutProject.getChangeInMoney().negate());
        courseList.setCommissionAmount(courseList.getAchievementAmount().multiply(courseList.getSalesCommission()));
        if (null != courseList.getSaleOneStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(changeOutProject.getChangeInPayMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(changeOutProject.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(changeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleOneNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleOneStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleOneStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleOneIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleOneRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.ZERO);
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils
//                    .add(BigDecimalUtils
//                                    .multiply(courseList.getAchievementAmount(),
//                                            BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
//                            BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(changeOutProject.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()));

            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            //todo 转出是否按照卡付提成扣减
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));

            achiCommEntity.setCashAchi(BigDecimal.ZERO);
            achiCommEntity.setCardAchi(BigDecimal.ZERO);

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleTwoStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(changeOutProject.getChangeInPayMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(changeOutProject.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(changeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleTwoNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleTwoStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleTwoStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleTwoIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleTwoRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.ZERO);
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(changeOutProject.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));

            achiCommEntity.setCashAchi(BigDecimal.ZERO);
            achiCommEntity.setCardAchi(BigDecimal.ZERO);


            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleThreeStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(changeOutProject.getChangeInPayMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(changeOutProject.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(changeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleThreeNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleThreeStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleThreeStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleThreeIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleThreeRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.ZERO);
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(changeOutProject.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));


            achiCommEntity.setCashAchi(BigDecimal.ZERO);
            achiCommEntity.setCardAchi(BigDecimal.ZERO);

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFourStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(changeOutProject.getChangeInPayMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(changeOutProject.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(changeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFourNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFourStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFourStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFourIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFourRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.ZERO);
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(changeOutProject.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));

            achiCommEntity.setCashAchi(BigDecimal.ZERO);
            achiCommEntity.setCardAchi(BigDecimal.ZERO);

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFiveStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(changeOutProject.getChangeInPayMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(changeOutProject.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(changeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFiveNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFiveStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFiveStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFiveIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFiveRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.ZERO);
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(changeOutProject.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD)));

            achiCommEntity.setCashAchi(BigDecimal.ZERO);
            achiCommEntity.setCardAchi(BigDecimal.ZERO);

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleSixStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(changeOutProject.getChangeInPayMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(changeOutProject.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(changeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleSixNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleSixStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleSixStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleSixIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleSixRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.ZERO);
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(changeOutProject.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD)));

            achiCommEntity.setCashAchi(BigDecimal.ZERO);
            achiCommEntity.setCardAchi(BigDecimal.ZERO);

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleSevenStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(changeOutProject.getChangeInPayMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(changeOutProject.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(changeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleSevenNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleSevenStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleSevenStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleSevenIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleSevenRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.ZERO);
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(changeOutProject.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD)));

            achiCommEntity.setCashAchi(BigDecimal.ZERO);
            achiCommEntity.setCardAchi(BigDecimal.ZERO);

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleEightStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(changeOutProject.getChangeInPayMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(changeOutProject.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(changeOutProject.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleEightNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleEightStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleEightStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleEightIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleEightRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimal.ZERO);
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(changeOutProject.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD)));

            achiCommEntity.setCashAchi(BigDecimal.ZERO);
            achiCommEntity.setCardAchi(BigDecimal.ZERO);

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        return entities;
    }
    /*
     * 业务员列表设置返回值
     * */
    public List<AchiCommEntity> getAchiCommList(CardChangeInProject courseList){
        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");

        BaseProject baseProject = ssmProjectService.selectByPrimaryKey(courseList.getProjectId());
        BigDecimal cooperationCashAchi=new BigDecimal("0");//合作现付业绩
        //isCooperation 比例brokerage 1是比例 0是固定smokeCommissionWay
        if(baseProject.getIsCooperation()==1){
            if(baseProject.getSmokeCommissionWay()!=null&&baseProject.getSmokeCommissionWay()==1){//合作按比例
                cooperationCashAchi=baseProject.getBrokerage().divide(hundredBD).multiply(courseList.getChangeInPayMoney());
            }else{//合作按固定
                cooperationCashAchi=baseProject.getBrokerage();
            }
        }
        courseList.setChangeInPayMoney(courseList.getChangeInPayMoney().subtract(cooperationCashAchi));
        courseList.setChangeOutMoney(courseList.getChangeOutMoney().add(BigDecimal.valueOf(0)));
        courseList.setAchievementAmount(courseList.getChangeInMoney());
        courseList.setCommissionAmount(courseList.getAchievementAmount().multiply(courseList.getSalesCommission()));
        if (null != courseList.getSaleOneStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleOneNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleOneStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleOneStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleOneIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleOneRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils
                    .add(BigDecimalUtils
                                    .multiply(courseList.getAchievementAmount(),
                                            BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));

            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleTwoStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleTwoNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleTwoStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleTwoStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleTwoIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleTwoRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleThreeStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleThreeNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleThreeStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleThreeStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleThreeIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleThreeRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFourStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFourNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFourStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFourStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFourIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFourRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        return entities;
    }

    public List<AchiCommEntity> getAchiCommListByJz(CardChangeInProject courseList){
        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");

        BaseProject baseProject = ssmProjectService.selectByPrimaryKey(courseList.getProjectId());
        BigDecimal cooperationCashAchi=new BigDecimal("0");//合作现付业绩
        //isCooperation 比例brokerage 1是比例 0是固定smokeCommissionWay
        if(baseProject.getIsCooperation()==1){
            if(baseProject.getSmokeCommissionWay()!=null&&baseProject.getSmokeCommissionWay()==1){//合作按比例
                cooperationCashAchi=baseProject.getBrokerage().divide(hundredBD).multiply(courseList.getChangeInPayMoney());
            }else{//合作按固定
                cooperationCashAchi=baseProject.getBrokerage().multiply(courseList.getChangeInPayMoney().divide(courseList.getChangeInMoney(),10,BigDecimal.ROUND_HALF_UP));
            }
        }
        courseList.setChangeInPayMoney(courseList.getChangeInPayMoney().subtract(cooperationCashAchi));
        courseList.setAchievementAmount(courseList.getChangeInMoney());
        courseList.setCommissionAmount(courseList.getChangeInPayMoney().multiply(courseList.getSalesCommission())
//                .add(courseList.getChangeOutMoney().multiply(courseList.getCardSalesCommission()))
        );
        if (null != courseList.getSaleOneStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleOneNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleOneStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleOneStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleOneIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleOneRatio());
            achiCommEntity.setSaleAchievementAmount(courseList.getChangeInPayMoney().multiply(courseList.getSaleOneRatio().divide(hundredBD)));
//            achiCommEntity.setSaleAchievementAmount(
//                    BigDecimalUtils.add(
//                            BigDecimalUtils
//                                    .multiply(courseList.getAchievementAmount(),
//                                            BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)), BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(courseList.getCommissionAmount().multiply(courseList.getSaleOneRatio().divide(hundredBD)));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(courseList.getChangeOutMoney().multiply(courseList.getCardSalesCommission()).multiply(courseList.getSaleOneRatio().divide(hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashCoopAchi(cooperationCashAchi.multiply(courseList.getSaleOneRatio().divide(hundredBD)));
            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleTwoStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleTwoNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleTwoStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleTwoStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleTwoIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleTwoRatio());
            achiCommEntity.setSaleAchievementAmount(courseList.getChangeInPayMoney().multiply(courseList.getSaleTwoRatio().divide(hundredBD)));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(courseList.getCommissionAmount().multiply(courseList.getSaleTwoRatio().divide(hundredBD)));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCashCoopAchi(cooperationCashAchi.multiply(courseList.getSaleTwoRatio().divide(hundredBD)));
            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleThreeStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleThreeNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleThreeStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleThreeStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleThreeIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleThreeRatio());
            achiCommEntity.setSaleAchievementAmount(courseList.getChangeInPayMoney().multiply(courseList.getSaleThreeRatio().divide(hundredBD)));
            achiCommEntity.setSaleCommissionAmount(courseList.getCommissionAmount().multiply(courseList.getSaleThreeRatio().divide(hundredBD)));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(achiCommEntity.getChangeOutMoney().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCashCoopAchi(cooperationCashAchi.multiply(courseList.getSaleThreeRatio().divide(hundredBD)));
            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFourStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFourNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFourStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFourStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFourIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFourRatio());
            achiCommEntity.setSaleAchievementAmount(courseList.getChangeInPayMoney().multiply(courseList.getSaleFourRatio().divide(hundredBD)));
            achiCommEntity.setSaleCommissionAmount(courseList.getCommissionAmount().multiply(courseList.getSaleFourRatio().divide(hundredBD)));
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
//            achiCommEntity.setCardComm(courseList.getChangeOutMoney().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCashCoopAchi(cooperationCashAchi.multiply(courseList.getSaleFourRatio().divide(hundredBD)));
            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        return entities;
    }

    public List<AchiCommEntity> getAchiCommListByOut(CardChangeOutProject courseList){
//        Long accountId = courseList.getAccountId();
//        CourseAccount courseAccount = ssmCourseAccountService.selectByPrimaryKey(accountId);
        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");
//        BaseProject baseProject1 = new BaseProject();
//        baseProject1.setProjectNum(courseList.getProjectNum());
        BaseProject baseProject = ssmProjectService.selectByPrimaryKey(courseList.getCourseProjectId());
        BigDecimal cooperationCashAchi=new BigDecimal("0");//合作现付业绩
        //isCooperation 比例brokerage 1是比例 0是固定smokeCommissionWay
        if(baseProject.getIsCooperation()==1){
            if(baseProject.getSmokeCommissionWay()==1){//合作按比例
                cooperationCashAchi=baseProject.getBrokerage().multiply(courseList.getChangeOutMoney());
            }else{//合作按固定
                cooperationCashAchi=baseProject.getBrokerage();
            }
        }
//        courseList.setChangeOutMoney(courseList.getChangeOutMoney().subtract(cooperationCashAchi).multiply(BigDecimal.valueOf(-1)));
        courseList.setAchievementAmount((courseList.getChangeOutMoney().subtract(cooperationCashAchi)));
        courseList.setCommissionAmount(courseList.getAchievementAmount().multiply(baseProject.getSalesCommission()));
        cooperationCashAchi = cooperationCashAchi.multiply(BigDecimal.valueOf(-1));

        if (null != courseList.getSaleOneStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setCooperationAchi(cooperationCashAchi.multiply(courseList.getSaleOneRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
//            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(courseList.getDocDate());
//            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleOneNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleOneStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleOneStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleOneIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleOneRatio());

            achiCommEntity.setSaleAchievementAmount((BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                                    BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))))
                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)))
                    .multiply(BigDecimal.valueOf(-1)));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))
//                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))
//                    .multiply(BigDecimal.valueOf(-1))
            );

            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))
//                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))
//                    .multiply(BigDecimal.valueOf(-1))
            );

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleTwoStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setCooperationAchi(cooperationCashAchi.multiply(courseList.getSaleTwoRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
//            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(courseList.getDocDate());
//            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleTwoNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleTwoStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleTwoStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleTwoIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleTwoRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)))
                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)))
                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getAchievementAmount(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleThreeStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setCooperationAchi(cooperationCashAchi.multiply(courseList.getSaleThreeRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
//            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(courseList.getDocDate());
//            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleThreeNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleThreeStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleThreeStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleThreeIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleThreeRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)))
                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)))
                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFourStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setCooperationAchi(cooperationCashAchi.multiply(courseList.getSaleFourRatio().divide(hundredBD,10,BigDecimal.ROUND_HALF_UP)));
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
//            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_use);
            achiCommEntity.setDocDate(courseList.getDocDate());
//            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFourNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFourStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFourStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFourIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFourRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)))
                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)))
                    .multiply(BigDecimal.valueOf(-1))
            );
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        return entities;
    }

    /*
     * 业务员列表设置返回值
     * */
    public List<AchiCommEntity> getAchiCommListNew(CardChangeInProject courseList){
        CardChangeOutProject cardChangeOutProject = new CardChangeOutProject();
        cardChangeOutProject.setStoreId(courseList.getStoreId());
        cardChangeOutProject.setDocNum(courseList.getDocNum());
        cardChangeOutProject.setMemberId(courseList.getMemberId());
        List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.select(cardChangeOutProject);
        BigDecimal cardAchi=BigDecimal.valueOf(0);
        BigDecimal cashAchi=BigDecimal.valueOf(0);
        BigDecimal cardCom=BigDecimal.valueOf(0);
        BigDecimal cashCom=BigDecimal.valueOf(0);
        for (CardChangeOutProject changeOutProject : cardChangeOutProjects) {
            CourseAccount courseAccount = ssmCourseAccountService.selectByPrimaryKey(changeOutProject.getAccountId());
            BaseProject baseProject = ssmProjectService.selectByPrimaryKey(courseAccount.getCourseProjectId());
            BigDecimal salesAchievement = baseProject.getSalesAchievement();
            BigDecimal salesCommission = baseProject.getSalesCommission();
            BigDecimal cardSalesAchievement = baseProject.getCardSalesAchievement();
            BigDecimal cardSalesCommission = baseProject.getCardSalesCommission();


        }

        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");
        if (null != courseList.getSaleOneStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleOneNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleOneStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleOneStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleOneIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleOneRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));

            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleTwoStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleTwoNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleTwoStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleTwoStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleTwoIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleTwoRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleThreeStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleThreeNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleThreeStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleThreeStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleThreeIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleThreeRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFourStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getTransactionMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFourNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFourStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFourStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFourIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFourRatio());
            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardAchievementAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD))));
            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(courseList.getCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)),
                    BigDecimalUtils.multiply(courseList.getCardCommissionAmount(),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD))));
            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));
            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
            entities.add(achiCommEntity);
        }
        return entities;
    }

    @Override
    public List<CardChangeList> selectListSalem(CardChangeList cardChangeList){
        return dao.selectListSalem(cardChangeList);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateState(CardChangeListRequest cardChangeListRequest, String loginAccount) throws SmsException {
        int state = 0;
        CardChangeList cardChangeList = dao.selectByPrimaryKey(cardChangeListRequest.getId());
        Set<String> keys = redisClient.keys(getStaffKey(loginAccount) + "*");
        if(1==cardChangeListRequest.getState()){//送审
            if(0==cardChangeList.getState() || 2==cardChangeList.getState()|| 4==cardChangeList.getState()){
                cardChangeList.setState(1);
                state = dao.updateByPrimaryKeySelective(cardChangeList);
            }else{
                throw new SmsException(ResponseCode.MSG,"当前状态不允许送审");
            }
        }else if(2==cardChangeListRequest.getState()){ //回收
            if(1==cardChangeList.getState()){
                cardChangeList.setState(2);
                state = dao.updateByPrimaryKeySelective(cardChangeList);
            }else{
                throw new SmsException(ResponseCode.MSG,"当前状态不允许回收");
            }
        }else if(3==cardChangeListRequest.getState()){ //审核
            if(1==cardChangeList.getState()){

                if (keys.size() > 0){
                    String key =  new ArrayList<>(keys).get(0);
                    StaffResponse staffResponse = redisClient.get(key);
                    cardChangeList.setAuditId(staffResponse.getId());
                    cardChangeList.setAuditBy(staffResponse.getStaffName());
                    cardChangeList.setAuditDate(new Date());
                }
                cardChangeList.setState(3);
                state = dao.updateByPrimaryKeySelective(cardChangeList);
                if(state>0){
                    CardChangeInProject cardChangeInProject = new CardChangeInProject();
                    cardChangeInProject.setStoreId(cardChangeList.getStoreId());
                    cardChangeInProject.setDocNum(cardChangeList.getDocNum());
                    CardChangeInProject cardChangeInProject1 = ssmCardChangeInProjectService.selectOne(cardChangeInProject);
                    CardChangeInProject audit = ssmCardChangeInProjectService.audit(cardChangeList, cardChangeInProject1);

                    CardChangeOutProjectRequest cardChangeOutProject = new CardChangeOutProjectRequest();
                    cardChangeOutProject.setStoreId(cardChangeList.getStoreId());
                    cardChangeOutProject.setDocNum(cardChangeList.getDocNum());
                    List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.selectList(cardChangeOutProject);
                    ssmCardChangeOutProjectService.inserts(cardChangeList,cardChangeOutProjects);

                    if (1 == cardChangeList.getIsDebt()){
                        DebtListRequest debtListRequest = new DebtListRequest();
                        BeanUtils.copyProperties(cardChangeList,debtListRequest);
                        debtListRequest.setTradeId(cardChangeInProject1.getProjectId());
                        debtListRequest.setTradeName(cardChangeInProject1.getProjectName());
                        debtListRequest.setTradeMoney(cardChangeInProject1.getChangeInMoney());
                        debtListRequest.setDocId(cardChangeList.getId());
                        debtListRequest.setDocNum(cardChangeList.getDocNum());
                        debtListRequest.setDocType(Constant.doc_type_card_change);
                        debtListRequest.setAccountId(cardChangeInProject1.getAccountId());
                        debtListRequest.setStaffLists(getStaffValue(cardChangeInProject));
                        debtListRequest.setState(0);
                        debtListRequest.setDocDate(cardChangeList.getDocDate());
                        debtListRequest.setRepayCount(cardChangeInProject1.getCourseRestCount());
                        debtListRequest.setRepayConsumeCount(cardChangeInProject1.getCourseConsumeCount());
                        ssmDebtService.addDebt(debtListRequest);
                    }
                }

            }else{
                throw new SmsException(ResponseCode.MSG,"当前状态不允许审核");
            }
        }else if(4==cardChangeListRequest.getState()){ //反审核
            if(3==cardChangeList.getState()){
                if (keys.size() > 0){
                    String key =  new ArrayList<>(keys).get(0);
                    StaffResponse staffResponse = redisClient.get(key);
                    cardChangeList.setCancelId(staffResponse.getId());
                    cardChangeList.setCancelBy(staffResponse.getStaffName());
                    cardChangeList.setCancelDate(new Date());
                }
                cardChangeList.setState(4);
                PayList payList = new PayList();
                payList.setDocId(cardChangeList.getDocNum());
                List<PayList> payListList = ssmPayService.select(payList);
                if(payListList!=null&&payListList.size()>0) {
                    for (PayList list : payListList) {
                        list.setIsCancel(1);
                        ssmPayService.updateByNum(list);
                    }
                }
                state = dao.updateByPrimaryKeySelective(cardChangeList);
                if(state > 0 ){
                   this.cancels(cardChangeList, loginAccount);
                    DebtList debtListRequest = new DebtList();
                    debtListRequest.setDocId(cardChangeList.getId());
                    debtListRequest.setDocNum(cardChangeList.getDocNum());
                    debtListRequest.setDocType(Constant.doc_type_card_change);
                    ssmDebtService.delete(debtListRequest);
                    CardChangeOutProject cardChangeOutProject = new CardChangeOutProject();
                    cardChangeOutProject.setDocNum(debtListRequest.getDocNum());
                    List<CardChangeOutProject> select = ssmCardChangeOutProjectService.select(cardChangeOutProject);
                    for (CardChangeOutProject outProject : select) {
                        CourseAccount courseAccount = ssmCourseAccountService.selectByPrimaryKey(outProject.getAccountId());
                        CancelDebtList cancelDebtList = new CancelDebtList();
                        cancelDebtList.setDocNum(courseAccount.getCourseNum());
                        ssmCancelDebtListService.deleteByDocNum(cancelDebtList);
                    }
                }
            }else{
                throw new SmsException(ResponseCode.MSG,"当前状态不允许反审核");
            }
        }
        return state;
    }

    @Override
    public List<CardChangeList> selectFKJ(CardChangeList cardChangeList) {
        return dao.selectFKJ(cardChangeList);
    }
    @Override
    public List<CardChangeList> selectFKJByDate(CardChangeList cardChangeList) {
        return mapper.selectFKJByDate(cardChangeList);
    }


    @Override
    public List<CardChangeOutProjectResponse> selectOutList(Long storeId, String date) {
        Example example = new Example(CardChangeList.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId",storeId);
        criteria.andLike("docDate", date + "%");
        criteria.andEqualTo("state", 3);
        List<CardChangeList> cardChangeLists = dao.selectByExample(example);
        //List<CardChangeInProject> cardChangeInProjects = new ArrayList<>();
        List<CardChangeOutProject> cardChangeOutProjects = new ArrayList<>();
        for (CardChangeList cardChangeList : cardChangeLists) {
            Example examples = new Example(CardChangeOutProject.class);
            Example.Criteria criterias = examples.createCriteria();
            criterias.andEqualTo("docNum",cardChangeList.getDocNum());
            //List<CardChangeInProject> cardChangeInProjectlist = ssmCardChangeInProjectService.selectByExample(examples);
            List<CardChangeOutProject> cardChangeOutProjectlist = ssmCardChangeOutProjectService.selectByExample(examples);
            for (CardChangeOutProject cardChangeOutProject : cardChangeOutProjectlist) {
                cardChangeOutProjects.add(cardChangeOutProject);
            }
            /*for (CardChangeInProject cardChangeInProject : cardChangeOutProjectlist) {
                cardChangeOutProjects.add(cardChangeInProject);
            }*/
        }
        List<CardChangeOutProjectResponse> listResponses = new ArrayList<>();
        for (CardChangeOutProject cardChangeOutProject :cardChangeOutProjects) {
            CardChangeOutProjectResponse courseListResponse = new CardChangeOutProjectResponse();
            BeanUtils.copyProperties(cardChangeOutProject,courseListResponse);
            //设置业务人员列表
            List<AchiCommEntity> entities = this.getAchiCommList2(cardChangeOutProject);
            courseListResponse.setEntities(entities);
            for (AchiCommEntity entity : entities) {
                entity.setDocId(cardChangeOutProject.getId());
                BaseProject baseProject = new BaseProject();
                baseProject.setId(Long.valueOf(entity.getProjectId()));
                BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                entity.setProjectId(baseProject1.getProjectNum());
            }
            listResponses.add(courseListResponse);
        }
        return listResponses;
        /*List<CardChangeInProjectResponse> listResponses = new ArrayList<>();
        for (CardChangeInProject cardChangeInProject :cardChangeInProjects) {
            CardChangeInProjectResponse courseListResponse = new CardChangeInProjectResponse();
            BeanUtils.copyProperties(cardChangeInProject,courseListResponse);
            //设置业务人员列表
            List<AchiCommEntity> entities = this.getAchiCommList(cardChangeInProject);
            courseListResponse.setEntities(entities);
            for (AchiCommEntity entity : entities) {
                entity.setDocId(cardChangeInProject.getId());
                BaseProject baseProject = new BaseProject();
                baseProject.setId(Long.valueOf(entity.getProjectId()));
                BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                entity.setProjectId(baseProject1.getProjectNum());
            }
            listResponses.add(courseListResponse);
        }
        return listResponses;*/
    }

    @Override
    public List<CardChangeDayVo> selectByDay(List<Long> storeIds, Date startTime, Date endTime) {
        return dao.selectByDay(storeIds,startTime,endTime);
    }

    @Override
    public List<StoreDaily> selectByDayGroupByDateAndStoreId(StoreDailyRequest storeDailyRequest) {
        return dao.selectByDayGroupByDateAndStoreId(storeDailyRequest);
    }

    @Autowired
    private CardChangeListMapper mapper;
    @Override
    public List<CardChangeList> selectNew(CardChangeListRequest cardChangeListRequest) {
        return mapper.selectNew(cardChangeListRequest);
    }


    @Transactional(rollbackFor = Exception.class)
    public int cancels(CardChangeList cardChangeList,String loginAccount) throws SmsException {
        int i = 0;
//        CardChangeList cardChangeList = new CardChangeList();
//        BeanUtils.copyProperties(cardChangeListRequest, cardChangeList);
        //判断时间是否超过允许作废时间
        StoreParament storeParament = StoreParaUtils.getStorePara(cardChangeList.getStoreId(),Constant.service_ticke);
        Long days =  DateUtils.getDayDiff(cardChangeList.getDocDate(),new Date());
        if(!"0".equals(storeParament.getParamentValue())) {
            if (days.longValue() > Long.parseLong(storeParament.getParamentValue())) {
                throw new SmsException(ResponseCode.CANCEL_NOT_PERMISSION, "单据超过允许作废时间");
            }
        }
        //修改疗程单据状态
        cardChangeList.setState(4);
        cardChangeList.setCancelDate(new Date());
        //设置作废人信息
        if (redisClient.hasKey(getStaffKey(loginAccount))){
            StaffResponse staffResponse = redisClient.get(getStaffKey(loginAccount));
            cardChangeList.setCancelId(staffResponse.getId());
            cardChangeList.setCancelBy(staffResponse.getStaffName());
        }
        Set<String> keys = redisClient.keys(getStaffKey(loginAccount) + "*");
        //从redis查询 设置作废人信息 app使用
        if (keys.size() > 0){
            String key =  new ArrayList<>(keys).get(0);
            StaffResponse staffResponse = redisClient.get(key);
            cardChangeList.setCancelId(staffResponse.getId());
            cardChangeList.setCancelBy(staffResponse.getStaffName());
        }
        //转入疗程作废 账户扣减次数
        ssmCardChangeInProjectService.cancel(cardChangeList);
        //转出疗程作废 账户添加次数
        ssmCardChangeOutProjectService.cancel(cardChangeList);
        //欠款 删除欠款记录
        if (1 == cardChangeList.getIsDebt()){
            DebtListRequest debtListRequest = new DebtListRequest();
            debtListRequest.setDocId(cardChangeList.getId());
            debtListRequest.setMemberId(cardChangeList.getMemberId());
            debtListRequest.setStoreId(cardChangeList.getStoreId());
            ssmDebtService.deleteDebt(debtListRequest);
        }
        try {
            i = dao.updateByPrimaryKeySelective(cardChangeList);
            Salesman salesman = new Salesman();
            salesman.setOrderNum(String.valueOf(cardChangeList.getDocNum()));
            salesman.setOrderType(3);
            List<Salesman> salesmen = ssmSalesmanService.selectList(salesman);
            for (Salesman salesman1 : salesmen) {
                salesman1.setState(1);
                ssmSalesmanService.updateNotNull(salesman1);
            }
        }catch (Exception e){
            log.error("SsmCardChangeServiceImpl.cancel:", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new SmsException(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
        }
        //将评价单进行删除操作
        MemberCs memberCs = new MemberCs();
        memberCs.setDocId(cardChangeList.getId());
        ssmMemberCsService.delete(memberCs);
        return i;
    }


    /*
     * 业务员赋值
     * */
    public List<StaffRequest> getStaffValue(CardChangeInProject cardChangeInProject){
        List<StaffRequest> staffRequests = new ArrayList<>();
        if(null != cardChangeInProject.getSaleOneStaffId()){
            StaffRequest staffRequest= new StaffRequest();
            staffRequest.setId(cardChangeInProject.getSaleOneStaffId());
            staffRequest.setStaffName(cardChangeInProject.getSaleOneStaffName());
            staffRequest.setIdentityCard(cardChangeInProject.getSaleOneIdentity());
            staffRequest.setRatio(cardChangeInProject.getSaleOneRatio());
            staffRequest.setBrandNumber(cardChangeInProject.getSaleOneNumber());
            staffRequests.add(staffRequest);
        }
        if(null != cardChangeInProject.getSaleTwoStaffId()){
            StaffRequest staffRequest= new StaffRequest();
            staffRequest.setId(cardChangeInProject.getSaleTwoStaffId());
            staffRequest.setStaffName(cardChangeInProject.getSaleTwoStaffName());
            staffRequest.setIdentityCard(cardChangeInProject.getSaleTwoIdentity());
            staffRequest.setRatio(cardChangeInProject.getSaleTwoRatio());
            staffRequest.setBrandNumber(cardChangeInProject.getSaleTwoNumber());
            staffRequests.add(staffRequest);
        }
        if(null != cardChangeInProject.getSaleThreeStaffId()){
            StaffRequest staffRequest= new StaffRequest();
            staffRequest.setId(cardChangeInProject.getSaleThreeStaffId());
            staffRequest.setStaffName(cardChangeInProject.getSaleThreeStaffName());
            staffRequest.setIdentityCard(cardChangeInProject.getSaleThreeIdentity());
            staffRequest.setRatio(cardChangeInProject.getSaleThreeRatio());
            staffRequest.setBrandNumber(cardChangeInProject.getSaleThreeNumber());
            staffRequests.add(staffRequest);
        }
        if(null != cardChangeInProject.getSaleFourStaffId()){
            StaffRequest staffRequest= new StaffRequest();
            staffRequest.setId(cardChangeInProject.getSaleFourStaffId());
            staffRequest.setStaffName(cardChangeInProject.getSaleFourStaffName());
            staffRequest.setIdentityCard(cardChangeInProject.getSaleFourIdentity());
            staffRequest.setRatio(cardChangeInProject.getSaleFourRatio());
            staffRequest.setBrandNumber(cardChangeInProject.getSaleFourNumber());
            staffRequests.add(staffRequest);
        }
        return staffRequests;
    }

    /*
     * 业务员列表设置返回值
     * */
    public List<AchiCommEntity> getAchiCommList2(CardChangeOutProject courseList){
        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");
        if (null != courseList.getSaleOneStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getCourseProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getCourseProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleOneNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleOneStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleOneStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleOneIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleOneRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                            BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));

            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.multiply(courseList.getCommissionAmount(),
                            BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));

            /*achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));*/

            /*achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
*/
            achiCommEntity.setCardAchi(achiCommEntity.getSaleAchievementAmount());
            achiCommEntity.setCardComm(achiCommEntity.getSaleCommissionAmount());

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleTwoStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getCourseProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getCourseProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleTwoNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleTwoStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleTwoStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleTwoIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleTwoRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                    BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));

            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.multiply(courseList.getCommissionAmount(),
                    BigDecimalUtils.div(courseList.getSaleTwoRatio(),hundredBD)));

            /*achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));*/

            /*achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
*/
            achiCommEntity.setCardAchi(achiCommEntity.getSaleAchievementAmount());
            achiCommEntity.setCardComm(achiCommEntity.getSaleCommissionAmount());

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleThreeStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getCourseProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getCourseProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleThreeNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleThreeStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleThreeStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleThreeIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleThreeRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                    BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));

            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.multiply(courseList.getCommissionAmount(),
                    BigDecimalUtils.div(courseList.getSaleThreeRatio(),hundredBD)));

            /*achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));*/

            /*achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
*/
            achiCommEntity.setCardAchi(achiCommEntity.getSaleAchievementAmount());
            achiCommEntity.setCardComm(achiCommEntity.getSaleCommissionAmount());

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFourStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getCourseProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getCourseProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFourNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFourStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFourStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFourIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFourRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                    BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));

            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.multiply(courseList.getCommissionAmount(),
                    BigDecimalUtils.div(courseList.getSaleFourRatio(),hundredBD)));

            /*achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));*/

            /*achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
*/
            achiCommEntity.setCardAchi(achiCommEntity.getSaleAchievementAmount());
            achiCommEntity.setCardComm(achiCommEntity.getSaleCommissionAmount());

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleFiveStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getCourseProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getCourseProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleFiveNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleFiveStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleFiveStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleFiveIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleFiveRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                    BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD)));

            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.multiply(courseList.getCommissionAmount(),
                    BigDecimalUtils.div(courseList.getSaleFiveRatio(),hundredBD)));

            /*achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));*/

            /*achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
*/
            achiCommEntity.setCardAchi(achiCommEntity.getSaleAchievementAmount());
            achiCommEntity.setCardComm(achiCommEntity.getSaleCommissionAmount());

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleSixStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getCourseProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getCourseProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleSixNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleSixStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleSixStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleSixIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleSixRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                    BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD)));

            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.multiply(courseList.getCommissionAmount(),
                    BigDecimalUtils.div(courseList.getSaleSixRatio(),hundredBD)));

            /*achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));*/

            /*achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
*/
            achiCommEntity.setCardAchi(achiCommEntity.getSaleAchievementAmount());
            achiCommEntity.setCardComm(achiCommEntity.getSaleCommissionAmount());

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleSevenStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getCourseProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getCourseProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleSevenNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleSevenStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleSevenStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleSevenIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleSevenRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                    BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD)));

            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.multiply(courseList.getCommissionAmount(),
                    BigDecimalUtils.div(courseList.getSaleSevenRatio(),hundredBD)));

            /*achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));*/

            /*achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
*/
            achiCommEntity.setCardAchi(achiCommEntity.getSaleAchievementAmount());
            achiCommEntity.setCardComm(achiCommEntity.getSaleCommissionAmount());

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        if (null != courseList.getSaleEightStaffId()){
            AchiCommEntity achiCommEntity = new AchiCommEntity();
            achiCommEntity.setMoney(courseList.getChangeOutMoney());
            achiCommEntity.setMemberNum(String.valueOf(courseList.getMemberId()));
            achiCommEntity.setMemberName(courseList.getMemberName());
            achiCommEntity.setProjectId(String.valueOf(courseList.getCourseProjectId()));
            achiCommEntity.setDocNum(courseList.getDocNum());
            achiCommEntity.setDocType(Constant.doc_type_card_change);
            achiCommEntity.setDocDate(courseList.getDocDate());
            achiCommEntity.setTradeName(courseList.getCourseProjectName());
            achiCommEntity.setBrandNumber(courseList.getSaleEightNumber());
            achiCommEntity.setSaleStaffId(courseList.getSaleEightStaffId());
            achiCommEntity.setSaleStaffName(courseList.getSaleEightStaffName());
            achiCommEntity.setSaleIdentityCard(courseList.getSaleEightIdentity());
            achiCommEntity.setSaleRatio(courseList.getSaleEightRatio());

            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.multiply(courseList.getAchievementAmount(),
                    BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD)));

            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.multiply(courseList.getCommissionAmount(),
                    BigDecimalUtils.div(courseList.getSaleEightRatio(),hundredBD)));

            /*achiCommEntity.setCashAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeInPayMoney(),courseList.getSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),courseList.getSalesCommission()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));*/

            /*achiCommEntity.setCardAchi(BigDecimalUtils.multiply(BigDecimalUtils.multiply(courseList.getChangeOutMoney(),courseList.getCardSalesAchievement()),BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
            achiCommEntity.setCardComm(achiCommEntity.getCardAchi().multiply(courseList.getCardSalesCommission()).multiply(BigDecimalUtils.div(courseList.getSaleOneRatio(),hundredBD)));
*/
            achiCommEntity.setCardAchi(achiCommEntity.getSaleAchievementAmount());
            achiCommEntity.setCardComm(achiCommEntity.getSaleCommissionAmount());

            if(null == achiCommEntity.getCashAchi()){
                achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardAchi() ){
                achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCashComm()){
                achiCommEntity.setCashComm(BigDecimal.valueOf(0));
            }
            if(null == achiCommEntity.getCardComm()){
                achiCommEntity.setCardComm(BigDecimal.valueOf(0));
            }
            achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
            achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

            entities.add(achiCommEntity);
        }
        return entities;
    }

}
