package cn.superdesk.uniorder.service.order._leaveover.impl;

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.exception.UnifiedOrderRuntimeException;
import cn.superdesk.uniorder.common.exception.constants.ExceptionMsg;
import cn.superdesk.uniorder.common.numerical.AnDateHelper;
import cn.superdesk.uniorder.common.numerical.AnIntegerUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.JwtUtil;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.accounting.unified.customer.AccountingUnifiedCustomer;
import cn.superdesk.uniorder.dao.entity.accounting.unified.customer.AccountingUnifiedCustomerOrder;
import cn.superdesk.uniorder.dao.entity.sys.SysBackAccount;
import cn.superdesk.uniorder.dao.entity.sys.SysInvoice;
import cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerMapper;
import cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerMapperEx;
import cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerOrderMapper;
import cn.superdesk.uniorder.dao.mapper.accounting.unified.customer.AccountingUnifiedCustomerOrderMapperEx;
import cn.superdesk.uniorder.dao.mapper.sys.SysBackAccountMapper;
import cn.superdesk.uniorder.dao.mapper.sys.SysInvoiceMapper;
import cn.superdesk.uniorder.dto.vo.inv.ViewBackAccountManage;
import cn.superdesk.uniorder.dto.vo.inv.ViewInvoiceDetailsHead;
import cn.superdesk.uniorder.dto.vo.inv.ViewInvoiceDetailsList;
import cn.superdesk.uniorder.dto.vo.inv.ViewInvoiceManage;
import cn.superdesk.uniorder.service.order._leaveover.SysInvoiceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@Service
public class SysInvoiceServiceImpl implements SysInvoiceService {


    @Autowired
    SysInvoiceMapper sysInvoiceMapper;

    @Autowired
    SysBackAccountMapper sysBackAccountMapper;


    @Autowired
    AccountingUnifiedCustomerMapper        accountingUnifiedCustomerMapper;
    @Autowired
    AccountingUnifiedCustomerOrderMapper   accountingUnifiedCustomerOrderMapper;
    @Autowired
    AccountingUnifiedCustomerMapperEx      accountingUnifiedCustomerMapperEx;
    @Autowired
    AccountingUnifiedCustomerOrderMapperEx accountingUnifiedCustomerOrderMapperEx;


    @Override
    public int insertSelective(SysInvoice t) {

        return sysInvoiceMapper.insertSelective(t);
    }

    @Override
    public int updateByPrimaryKeySelective(SysInvoice t) {

        return sysInvoiceMapper.updateByPrimaryKeySelective(t);
    }

    @Override
    public void deleteObj(Long id) {

        sysInvoiceMapper.deleteByPrimaryKey(id);
    }


    @Override
    public SysInvoice findById(Long id) {

        return sysInvoiceMapper.selectByPrimaryKey(id);
    }


    @Override
    public List<SysInvoice> findAll(Map<String, Object> queryMap) {

        return sysInvoiceMapper.findAll(queryMap);
    }

    @Override
    public PageInfo<SysInvoice> findByPaging(Map<String, Object> params, Integer pageNo, Integer pageSize) {

        return null;
    }


    @Override
    public R<List<ViewInvoiceManage>> findInvoiceManageViewPage(Map<String, Object> params, int pageNo, int pageSize) {

        PageHelper.startPage(pageNo, pageSize);
        List<ViewInvoiceManage> ls = sysInvoiceMapper.findInvoiceManageViewPage(params);


        Map<String, Object> returnHeadMap  = new HashMap<>();
        BigDecimal          invoiceAccount = BigDecimal.ZERO;
        Integer             billNum        = 0;
        Integer             invoiceNum     = 0;
        for (ViewInvoiceManage vi : ls) {
            invoiceAccount = invoiceAccount.add(vi.getInvoiceAccount());
            ++billNum;
            ++invoiceNum;
        }
        returnHeadMap.put("billNum", billNum);//订单数
        returnHeadMap.put("invoiceNum", invoiceNum);//发票数
        returnHeadMap.put("invoiceAccount", invoiceAccount);//发票金额


        PageInfo<ViewInvoiceManage> page = new PageInfo<ViewInvoiceManage>(ls);
        PageHelper.clearPage();
        return new R<List<ViewInvoiceManage>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), ls, returnHeadMap);

    }

    @Override
    public List<ViewInvoiceDetailsList> findInvoiceDetailsList(Map<String, Object> params) {

        List<ViewInvoiceDetailsList> ls = sysInvoiceMapper.findInvoiceDetailsList(params);
        return ls;

    }


    // 要加事务
    @Override
    @Transactional
    public Integer confirmBackAccount(List<Map> mailTickRegisterList, String token) {

        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		/*mdzId
		orderId
		backAccountTime
		backAccountRemark
		backAccount	
		 */


        for (Map mailTickRegisterMap : mailTickRegisterList) {


            String mdzId             = (String) mailTickRegisterMap.get("mdzId");
            String orderId           = (String) mailTickRegisterMap.get("orderId");
            String backAccountTime   = (String) mailTickRegisterMap.get("backAccountTime");
            String backAccountRemark = (String) mailTickRegisterMap.get("backAccountRemark");

            if (mailTickRegisterMap.get("backAccount") instanceof String) {

            } else {
                // 报异常
                throw new UnifiedOrderRuntimeException(ExceptionMsg.SYS_ERROR.getCode(), "回款总金额参数格式错误");
            }

            String backAccountStr = (String) mailTickRegisterMap.get("backAccount");//发票号

            if (StringUtils.isEmpty(backAccountStr)) {
                // 报异常
                throw new UnifiedOrderRuntimeException(ExceptionMsg.SYS_ERROR.getCode(), "回款总金额不能为空");
            }

            if ("0".equals(backAccountStr)) {
                // 回款金额为0 不操作处理
                continue;
                //throw new MyException(ExceptionMsg.SYS_ERROR.getCode(),"回款总金额不能为0");
            }

            BigDecimal backAccount = new BigDecimal(backAccountStr);


            SysBackAccount sysBackAccount = new SysBackAccount();
            sysBackAccount.setDzMainId(Long.decode(mdzId));
            sysBackAccount.setDzOrderId(Long.decode(orderId));
            sysBackAccount.setBackAccountTime(AnDateHelper.parseToDate(backAccountTime, AnDateHelper.DATE_TIME_STRING));
            sysBackAccount.setBackOperationTime(DateUtil.date());
            sysBackAccount.setBackAccountRemark(backAccountRemark);


            sysBackAccount.setBackAccount(backAccount);
            sysBackAccount.setBackAccountPersonId(AnIntegerUtils.getInteger(loginSysUser.getSysUserId()));


            // 当前已回款金额
            BigDecimal yetBackAccount = BigDecimal.ZERO;

            Map<String, Object> queryMap = new HashMap<>();
            queryMap.put("mdzId", Integer.decode(mdzId));
            queryMap.put("orderId", Integer.decode(orderId));
            List<SysBackAccount> listSysBackAccount = sysBackAccountMapper.findAll(queryMap);

            for (SysBackAccount sb : listSysBackAccount) {
                yetBackAccount = yetBackAccount.add(sb.getBackAccount());
            }


            BigDecimal billPrice = BigDecimal.ZERO;//订单价格

            queryMap = new HashMap<>();
            queryMap.put("dzId", Integer.decode(mdzId));
            // 查的dz_order.id
            queryMap.put("orderTableId", Integer.decode(orderId));
            List<AccountingUnifiedCustomerOrder> accountingUnifiedCustomerOrderList = accountingUnifiedCustomerOrderMapperEx.findAll(queryMap);
            if (accountingUnifiedCustomerOrderList.size() == 1) {
                AccountingUnifiedCustomerOrder viewDzOrder = accountingUnifiedCustomerOrderList.get(0);
                billPrice = viewDzOrder.getPrice();
            }


            // TODO
            // 回款金额不能为空
            // 回款总金额不能大余订单金额
            BigDecimal totalBackAccount = yetBackAccount.add(backAccount);
            if (totalBackAccount.compareTo(billPrice) == 1) {
                //报异常
                throw new UnifiedOrderRuntimeException(ExceptionMsg.SYS_ERROR.getCode(), "回款总金额不能大于订单金额");
            }


            sysBackAccountMapper.insertSelective(sysBackAccount);


            // 订单级回款状态返写
            queryMap = new HashMap<>();
            queryMap.put("mdzId", Integer.decode(mdzId));
            queryMap.put("orderId", Integer.decode(orderId));
            List<SysInvoice> listSysInvoice = sysInvoiceMapper.findAll(queryMap);
            if (listSysInvoice.size() == 1) {
                SysInvoice sysInvoice       = listSysInvoice.get(0);
                SysInvoice updateSysInvoice = new SysInvoice();
                updateSysInvoice.setId(sysInvoice.getId());

                //回款状态  (0未回款\1部分回款\2全部回款
                Integer backStatus = 0;//回款状态
                if (billPrice.compareTo(totalBackAccount) == 0) {
                    backStatus = 2;
                } else {
                    backStatus = 1;
                }
                updateSysInvoice.setBackStatus(backStatus);
                //回写发票表 回款状态
                sysInvoiceMapper.updateByPrimaryKeySelective(updateSysInvoice);//订单级回款状态返写
            }


            //回写帐单表 回款状态
            queryMap = new HashMap<>();
            queryMap.put("mdzId", Integer.decode(mdzId));
            List<SysInvoice> mdzSysInvoice     = sysInvoiceMapper.findAll(queryMap);
            int              allBackAccountNum = 0;//订单全部回款数量

            //回款状态  (0未回款\1部分回款\2全部回款
            for (SysInvoice si : mdzSysInvoice) {
                if (si.getBackStatus() == 2) {
                    ++allBackAccountNum;
                }
            }

            int dz_invstatus = 0;

            // 回款状态  (0未回款\1部分回款\2全部回款
            if (mdzSysInvoice.size() == allBackAccountNum) {
                dz_invstatus = 2;
            } else {
                dz_invstatus = 1;
            }
            AccountingUnifiedCustomer accountingUnifiedCustomer = new AccountingUnifiedCustomer();
            accountingUnifiedCustomer.setId(Long.decode(mdzId));
            accountingUnifiedCustomer.setBackAccountStatus(Integer.decode(String.valueOf(dz_invstatus)));
            accountingUnifiedCustomerMapper.updateByPrimaryKeySelective(accountingUnifiedCustomer);
            // 回写帐单表 回款状态
        }

        return mailTickRegisterList.size();
    }

    @Override
    @Transactional
    public Integer mailTickRegister(Map mailTickRegisterMap, String operationStr) {

		
		/*mdzId
		orderId
		expressCompanyId
		express_no*/


        //makeInvoiceStatus, #'开票状态 0未开票 1 已开票'

        //发票状态 0未邮寄 1已邮寄 2已作废
        //private Integer mailTickStatus; ==>数据库字段
        //"invoiceStatus": 0, //发票状态 0未邮寄 1已邮寄 2已作废

        operationStr = operationStr.trim();//去空格

        String mdzId            = (String) mailTickRegisterMap.get("mdzId");
        String orderId          = (String) mailTickRegisterMap.get("orderId");
        String expressCompanyId = (String) mailTickRegisterMap.get("expressCompanyId");
        String expressNo        = (String) mailTickRegisterMap.get("express_no");
        String invoiceNumber    = (String) mailTickRegisterMap.get("invoice_number");//发票号

        AccountingUnifiedCustomerOrder dzOrder = accountingUnifiedCustomerOrderMapper.selectByPrimaryKey(Long.decode(orderId));//查帐单对应的订单

        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("mdzId", Integer.decode(mdzId));
        queryMap.put("orderId", Integer.decode(orderId));
        List<SysInvoice> listSysInvoice = sysInvoiceMapper.findAll(queryMap);

        if (listSysInvoice.size() > 1) {

        } else if (listSysInvoice.size() == 1) {
            SysInvoice sysInvoice = listSysInvoice.get(0);

            if (operationStr.equals("mailTickRegister")) {
                sysInvoice.setExpressCompanyId(Long.decode(expressCompanyId));
                sysInvoice.setExpressNo(expressNo);
                // 发票状态 0未邮寄 1已邮寄 2已作废
                sysInvoice.setInvoiceStatus(1);
                sysInvoice.setMailTickTime(DateUtil.date());
            } else if (operationStr.equals("confirmInvoice")) {
                sysInvoice.setInvoiceNumber(invoiceNumber);
                sysInvoice.setInvoiceTime(DateUtil.date());
                sysInvoice.setMakeInvoiceStatus(1);//开票状态 0未开票 1 已开票
                sysInvoice.setInvoiceStatus(0);//发票状态 0未邮寄 1已邮寄 2已作废
            }
            sysInvoice.setMyOrdersn(dzOrder.getOrderSn());
            sysInvoiceMapper.updateByPrimaryKeySelective(sysInvoice);
        } else {//没有发票登记记录 要新增记录
            SysInvoice sysInvoice = new SysInvoice();
            sysInvoice.setDzMainId(Long.decode(mdzId));
            sysInvoice.setDzOrderId(Long.decode(orderId));

            if (operationStr.equals("mailTickRegister")) {
                sysInvoice.setExpressCompanyId(Long.decode(expressCompanyId));
                sysInvoice.setExpressNo(expressNo);
                sysInvoice.setInvoiceStatus(1);
                sysInvoice.setMailTickTime(DateUtil.date());
            } else if (operationStr.equals("confirmInvoice")) {
                sysInvoice.setInvoiceNumber(invoiceNumber);
                sysInvoice.setInvoiceTime(DateUtil.date());
                sysInvoice.setMakeInvoiceStatus(1);//开票状态 0未开票 1 已开票
                sysInvoice.setInvoiceStatus(0);//发票状态 0未邮寄 1已邮寄 2已作废
            }
            sysInvoice.setMyOrdersn(dzOrder.getOrderSn());
            sysInvoiceMapper.insertSelective(sysInvoice);
        }

        if (operationStr.equals("confirmInvoice")) {
            reverseRriteDZInvoiceStatus(mdzId);
        }

        return 1;
    }

    @Override
    public List<ViewInvoiceDetailsHead> getInvoiceDetailByInvoiceId(Map<String, Object> params) {

        List<ViewInvoiceDetailsHead> ls = sysInvoiceMapper.getInvoiceDetailByInvoiceId(params);
        return ls;
    }

    @Override
    public List<ViewInvoiceManage> findInvoiceManageList(Map<String, Object> params) {

        List<ViewInvoiceManage> ls = sysInvoiceMapper.findInvoiceManageViewPage(params);
        return ls;

    }

    @Override
    public R<List<ViewBackAccountManage>> getBackAccountManageData(Map<String, Object> params, int pageNo, int pageSize) {

        PageHelper.startPage(pageNo, pageSize);
        List<ViewBackAccountManage> ls = sysInvoiceMapper.getBackAccountManageData(params);

        Map<String, Object> returnHeadMap = new HashMap<>();
        BigDecimal          dzAccount     = BigDecimal.ZERO;
        Integer             billNum       = 0;
        Integer             dzNum         = 0;
        for (ViewBackAccountManage vi : ls) {
            dzAccount = dzAccount.add(vi.getInvoiceAccount());
            billNum = billNum + vi.getOrderNum();
            ++dzNum;
        }
        returnHeadMap.put("billNum", billNum);//订单数
        returnHeadMap.put("dzNum", dzNum);//对账单数
        returnHeadMap.put("invoiceAccount", dzAccount);//账单金额


        PageInfo<ViewBackAccountManage> page = new PageInfo<ViewBackAccountManage>(ls);
        PageHelper.clearPage();
        return new R<List<ViewBackAccountManage>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), ls, returnHeadMap);
        //ResponseResult<List<ViewBackAccountManage>> res= new ResponseResult<List<ViewBackAccountManage>>(page.getPageNum(), page.getPageSize(), (int)page.getTotal(), ls);
        //return res;
    }

    @Override
    public List<ViewBackAccountManage> getBackAccountDataRegisterData(Map<String, Object> params) {

        List<ViewBackAccountManage> ls = sysInvoiceMapper.getBackAccountDataRegisterData(params);
        return ls;
    }

    @Override
    public List<ViewBackAccountManage> getBackAccountManageList(Map<String, Object> params) {

        List<ViewBackAccountManage> ls = sysInvoiceMapper.getBackAccountManageData(params);
        return ls;
    }

    @Override
    public Map<String, Object> reInvoiceRegister(String mdzId, String orderId) {


        Map<String, Object> returnMap = new HashMap<>();
        Map<String, Object> queryMap  = new HashMap<>();
        queryMap.put("mdzId", Integer.decode(mdzId));
        queryMap.put("orderId", Integer.decode(orderId));

        List<SysInvoice> listSysInvoice = sysInvoiceMapper.findAll(queryMap);

        // 未回款才可以 重新登记
        if (listSysInvoice.size() == 1) {
            SysInvoice sysInvoice = listSysInvoice.get(0);

            // new update 保险点
            SysInvoice sysInvoiceUpdate = new SysInvoice();
            sysInvoiceUpdate.setId(sysInvoice.getId());
            // 发票状态 0未邮寄 1已邮寄 2已作废
            sysInvoiceUpdate.setInvoiceStatus(2);
            sysInvoiceUpdate.setMakeInvoiceStatus(0);//开票状态 0未开票 1 已开票
            // sysInvoiceUpdate.setInvoiceNumber("");

            sysInvoiceMapper.updateByPrimaryKeySelective(sysInvoiceUpdate);

            reverseRriteDZInvoiceStatus(mdzId);

            returnMap.put("success", "true");
        }

        return returnMap;
    }

    @Override
    @Transactional
    public Map<String, Object> importDZExcel(List<Map<String, String>> list) {

        // 需要考虑对帐单状态
        Map<String, Object> returnMap = new HashMap<>();

        int totalUpdateNum = 0;

        for (int i = 0; i < list.size(); i++) {

            Map<String, String> excelMap      = list.get(i);
            String              myOrderSn     = excelMap.get("myOrderSn");
            String              invoiceNumber = excelMap.get("invoiceNumber");

            String paramMdzId = "";

            Map<String, Object> queryMap = new HashMap<>();
            //queryMap.put("mdzId", Integer.decode(mdzId));
            //queryMap.put("orderId", Integer.decode(orderId));
            queryMap.put("myOrderSn", myOrderSn);
            List<SysInvoice> listSysInvoice = sysInvoiceMapper.findAll(queryMap);


            queryMap.put("myOrderSn", myOrderSn);
            List<AccountingUnifiedCustomerOrder> accountingUnifiedCustomerOrderList = accountingUnifiedCustomerOrderMapperEx.findAll(queryMap);//查帐单对应的订单
            if (accountingUnifiedCustomerOrderList.size() == 1) {
                paramMdzId = accountingUnifiedCustomerOrderList.get(0).getDzId().toString();
                AccountingUnifiedCustomer dzMain = accountingUnifiedCustomerMapper.selectByPrimaryKey(Long.decode(paramMdzId));

                // 对账单状态:0-未确认;1-已确认;-1-已取消;2-已拒绝;
                if (!dzMain.getAccountingStatus().equals(Byte.decode("1"))) {
                    //对帐单非已确认状态  不能导入发票
                    throw new UnifiedOrderRuntimeException(ExceptionMsg.SYS_ERROR.getCode(), myOrderSn + "订单对应对帐单:" + dzMain.getAccountingOrderSn() + "非已确认状态  不能导入发票");
                }
            } else {
                // 报异常
                throw new UnifiedOrderRuntimeException(ExceptionMsg.SYS_ERROR.getCode(), "二级编码:" + myOrderSn + "在系统中重复或找不到");
            }

            if (listSysInvoice.size() == 1) {
                // 报异常
                throw new UnifiedOrderRuntimeException(ExceptionMsg.SYS_ERROR.getCode(), "二级编码:" + myOrderSn + "在系统中重复");

            } else if (listSysInvoice.size() == 1) {
                SysInvoice sysInvoice = listSysInvoice.get(0);

                if (sysInvoice.getMakeInvoiceStatus() == 1) {
                    // 报异常
                    throw new UnifiedOrderRuntimeException(ExceptionMsg.SYS_ERROR.getCode(), "发票号:" + invoiceNumber + "已开票,不能在次导入");
                }

                paramMdzId = sysInvoice.getDzMainId().toString();
                SysInvoice updateSysInvoice = new SysInvoice();
                updateSysInvoice.setId(sysInvoice.getId());
                updateSysInvoice.setInvoiceNumber(invoiceNumber);
                updateSysInvoice.setInvoiceTime(DateUtil.date());
                updateSysInvoice.setMakeInvoiceStatus(1);///开票状态 0未开票 1 已开票
                updateSysInvoice.setInvoiceStatus(0);//发票状态 0未邮寄 1已邮寄 2已作废
                int updateNum = sysInvoiceMapper.updateByPrimaryKeySelective(updateSysInvoice);

                ++totalUpdateNum;
            } else {
                //queryMap=new HashMap<>();
                //queryMap.put("myOrderSn", myOrderSn);
                //List<DzOrder> ListDzOrder=dzOrderMapper.findAll(queryMap);//查帐单对应的订单
                if (accountingUnifiedCustomerOrderList.size() == 1) {

                    AccountingUnifiedCustomerOrder accountingUnifiedCustomerOrder = accountingUnifiedCustomerOrderList.get(0);

                    paramMdzId = accountingUnifiedCustomerOrder.getDzId().toString();

                    SysInvoice sysInvoice = new SysInvoice();
                    sysInvoice.setDzMainId(accountingUnifiedCustomerOrder.getDzId());
                    sysInvoice.setDzOrderId(accountingUnifiedCustomerOrder.getId());//取帐单 订单id
                    sysInvoice.setInvoiceNumber(invoiceNumber);
                    sysInvoice.setInvoiceTime(DateUtil.date());
                    sysInvoice.setMakeInvoiceStatus(1);//开票状态 0未开票 1 已开票
                    sysInvoice.setInvoiceStatus(0);//发票状态 0未邮寄 1已邮寄 2已作废
                    sysInvoiceMapper.insertSelective(sysInvoice);

                    ++totalUpdateNum;
                }

            }

            // 反写帐单开票状态
            log.info("importDZExcel paramMdzId===>" + paramMdzId);
            if (!StringUtils.isEmpty(paramMdzId)) {
                reverseRriteDZInvoiceStatus(paramMdzId);
            }


        }

        returnMap.put("totalNum", list.size());
        returnMap.put("totalUpdateNum", totalUpdateNum);

        return returnMap;
    }

    /**
     * 反写帐单开票状态
     *
     * @param accountingOrderId
     */
    private void reverseRriteDZInvoiceStatus(String accountingOrderId) {

        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("mdzId", Integer.decode(accountingOrderId));
        List<SysInvoice> mdzSysInvoice = sysInvoiceMapper.findAll(queryMap);

        queryMap = new HashMap<>();
        queryMap.put("dzId", Integer.decode(accountingOrderId));
        List<AccountingUnifiedCustomerOrder> accountingUnifiedCustomerOrderList = accountingUnifiedCustomerOrderMapperEx.findAll(queryMap);

        // 帐单的订单数
        int dzBillNum = accountingUnifiedCustomerOrderList.size();

        // 已开票数量
        int makeInvoiceNum = 0;
        for (SysInvoice si : mdzSysInvoice) {
            if (si.getMakeInvoiceStatus() == 1) {
                ++makeInvoiceNum;
            }
        }

        int dzInvstatus = 0;
        // 开票状态:0-未开票;1-已开票;2-部分开票;

        // 已开票数量要和帐单的订单数 比较
        if (dzBillNum == makeInvoiceNum) {
            // TODO 写死
            dzInvstatus = 1;
        } else if (0 != makeInvoiceNum && makeInvoiceNum < dzBillNum) {
            // TODO 写死
            dzInvstatus = 2;
        }

        AccountingUnifiedCustomer accountingUnifiedCustomer = new AccountingUnifiedCustomer();
        accountingUnifiedCustomer.setId(Long.decode(accountingOrderId));
        accountingUnifiedCustomer.setInvoiceStatus(dzInvstatus);
        accountingUnifiedCustomerMapper.updateByPrimaryKeySelective(accountingUnifiedCustomer);
        // 反写帐单开票状态
    }

}
