NutzCN Logo
短点 ChauffeurDetailService_b936b0d3
发布于 3006天前 作者 明天会吹什么风 2478 次浏览 复制 上一个帖子 下一个帖子
标签:

查看完整内容

package com.ihavecar.hirecar.modules.chauffeur.service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.util.HtmlUtils;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.ihavecar.hirecar.common.persistence.Page;
import com.ihavecar.hirecar.common.service.CrudService;
import com.ihavecar.hirecar.common.utils.DateUtils;
import com.ihavecar.hirecar.common.utils.JsonUtils;
import com.ihavecar.hirecar.common.utils.UserContextHolder;
import com.ihavecar.hirecar.modules.aggr.carinfoaggrprocess.constants.CarInfoAggrProcessStatus;
import com.ihavecar.hirecar.modules.aggr.carinfoaggrprocess.service.CarInfoAggrProcessService;
import com.ihavecar.hirecar.modules.aggr.dao.ChauffeurHireFeeListBasicDao;
import com.ihavecar.hirecar.modules.aggr.dao.ChauffeurHireFeeListPeriodDao;
import com.ihavecar.hirecar.modules.aggr.dao.ChauffeurHireFeePayHistoryRecordDao;
import com.ihavecar.hirecar.modules.aggr.dao.v2.CarChauffeurAduitDateDao;
import com.ihavecar.hirecar.modules.aggr.entity.ChauffeurHireFeeBasic;
import com.ihavecar.hirecar.modules.aggr.entity.ChauffeurHireFeePeriod;
import com.ihavecar.hirecar.modules.aggr.entity.v2.CarChauffeurAduitDate;
import com.ihavecar.hirecar.modules.aggr.parameters.BasicFeeItemAddParams;
import com.ihavecar.hirecar.modules.aggr.parameters.BasicFeeType;
import com.ihavecar.hirecar.modules.aggr.parameters.HireFeeItemEnum;
import com.ihavecar.hirecar.modules.aggr.parameters.PeriodFeeItemAddParams;
import com.ihavecar.hirecar.modules.aggr.service.ChauffeurHireFeeListService;
import com.ihavecar.hirecar.modules.aggr.service.v2.CarChauffeurAduitDateService;
import com.ihavecar.hirecar.modules.api.entity.mis.ChauffeurDetailResult;
import com.ihavecar.hirecar.modules.api.params.v2.TerminateVo;
import com.ihavecar.hirecar.modules.carinfo.dao.CarAccessAreaDao;
import com.ihavecar.hirecar.modules.carinfo.dao.CarBrandDao;
import com.ihavecar.hirecar.modules.carinfo.dao.CarChauffeurHirePoundageFeeDao;
import com.ihavecar.hirecar.modules.carinfo.dao.CarHirePackageDao;
import com.ihavecar.hirecar.modules.carinfo.dao.CarHirePackageMonthDao;
import com.ihavecar.hirecar.modules.carinfo.dao.CarInfoDao;
import com.ihavecar.hirecar.modules.carinfo.dao.CompanyDao;
import com.ihavecar.hirecar.modules.carinfo.entity.CarAccessArea;
import com.ihavecar.hirecar.modules.carinfo.entity.CarBrand;
import com.ihavecar.hirecar.modules.carinfo.entity.CarChauffeurHirePoundageFee;
import com.ihavecar.hirecar.modules.carinfo.entity.CarHirePackage;
import com.ihavecar.hirecar.modules.carinfo.entity.CarInfo;
import com.ihavecar.hirecar.modules.carinfo.entity.CarReorganize;
import com.ihavecar.hirecar.modules.carinfo.entity.Company;
import com.ihavecar.hirecar.modules.carinfo.service.CarInfoAssetsService;
import com.ihavecar.hirecar.modules.carinfo.service.CarInfoService;
import com.ihavecar.hirecar.modules.carinfo.service.CarReorganizeService;
import com.ihavecar.hirecar.modules.carinfo.service.CompanyService;
import com.ihavecar.hirecar.modules.chauffeur.constants.ChauffeurConstants;
import com.ihavecar.hirecar.modules.chauffeur.constants.ChauffeurOnceFeeStatus;
import com.ihavecar.hirecar.modules.chauffeur.constants.ChauffeurStatus;
import com.ihavecar.hirecar.modules.chauffeur.constants.ChauffeurStatusV2;
import com.ihavecar.hirecar.modules.chauffeur.constants.RiskRate;
import com.ihavecar.hirecar.modules.chauffeur.dao.CarChauffeurOnceFeeDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.CarChauffeurOnceFeeDetailDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurApplyDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurApplyMonthDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurBondsmanDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurContractDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurDetailDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurFamilyDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurFeeDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurProcessDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurRiskCtlDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurSnapshotDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurTakecarDao;
import com.ihavecar.hirecar.modules.chauffeur.dao.ChauffeurWorkDao;
import com.ihavecar.hirecar.modules.chauffeur.entity.CarChauffeurOnceFee;
import com.ihavecar.hirecar.modules.chauffeur.entity.CarChauffeurOnceFeeDetail;
import com.ihavecar.hirecar.modules.chauffeur.entity.Chauffeur;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurApply;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurApplyMonth;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurBondsman;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurDetail;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurDetailExportVoNew;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurFee;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurProcess;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurRiskCtl;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurRiskCtlV2;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurSnapshot;
import com.ihavecar.hirecar.modules.chauffeur.entity.ChauffeurTakecar;
import com.ihavecar.hirecar.modules.chauffeur.entity.DcarBaseCustomer;
import com.ihavecar.hirecar.modules.chauffeur.entity.FeeGather;
import com.ihavecar.hirecar.modules.chauffeur.entity.tmp.HireFeeInfo;
import com.ihavecar.hirecar.modules.chauffeur.entity.tmp.TmpCarInfo;
import com.ihavecar.hirecar.modules.chauffeur.exception.ChauffeurException;
import com.ihavecar.hirecar.modules.chauffeur.exception.GenFeesExceptiton;
import com.ihavecar.hirecar.modules.chauffeur.param.SaleStaff;
import com.ihavecar.hirecar.modules.chauffeur.utils.ChauffeurUtils;
import com.ihavecar.hirecar.modules.finance.dao.FeelistDao;
import com.ihavecar.hirecar.modules.finance.entity.ArriveListIncomeDo;
import com.ihavecar.hirecar.modules.finance.entity.Feelist;
import com.ihavecar.hirecar.modules.leadcokpit.service.SysUseErrorAggrInfoService;
import com.ihavecar.hirecar.modules.sale.service.SaleCommissionService;
import com.ihavecar.hirecar.modules.sys.constants.BusinessHisType;
import com.ihavecar.hirecar.modules.sys.dao.SysExceptionDao;
import com.ihavecar.hirecar.modules.sys.dao.UserDao;
import com.ihavecar.hirecar.modules.sys.entity.Attachment;
import com.ihavecar.hirecar.modules.sys.entity.Office;
import com.ihavecar.hirecar.modules.sys.entity.Role;
import com.ihavecar.hirecar.modules.sys.entity.SyncCarChauffeurAduitDateEntity;
import com.ihavecar.hirecar.modules.sys.entity.SysInc;
import com.ihavecar.hirecar.modules.sys.entity.User;
import com.ihavecar.hirecar.modules.sys.exception.BbuninessesHisException;
import com.ihavecar.hirecar.modules.sys.pojo.OldContactDataDO;
import com.ihavecar.hirecar.modules.sys.service.AttachmentService;
import com.ihavecar.hirecar.modules.sys.service.NotifyService;
import com.ihavecar.hirecar.modules.sys.service.SysExceptionService;
import com.ihavecar.hirecar.modules.sys.service.SysIncService;
import com.ihavecar.hirecar.modules.sys.service.implement.BbuninessesHisService;
import com.ihavecar.hirecar.modules.sys.utils.DictUtils;
import com.ihavecar.hirecar.modules.sys.utils.ParameterUtils;
import com.ihavecar.hirecar.modules.sys.utils.UserUtils;

/**
 * 客户详细信息Service
 *
 * @author ranyao
 * @version 2015-07-15
 */
@Service
@Transactional(readOnly = true)
public class ChauffeurDetailService extends CrudService<ChauffeurDetailDao, ChauffeurDetail> {

    @Resource
    private ChauffeurWorkService chauffeurWorkService;
    @Resource
    private ChauffeurFamilyService chauffeurFamilyService;
    @Resource
    private ChauffeurDetailDao chauffeurDetailDao;
    @Resource
    private ChauffeurApplyDao chauffeurApplyDao;
    @Resource
    private ChauffeurProcessDao chauffeurProcessDao;
    @Resource
    private ChauffeurRiskCtlDao chauffeurRiskCtlDao;
    @Resource
    public ChauffeurProcessService chauffeurProcessService;
    //    @Resource
//    private ChauffeurTakecarService takecarService;
    @Resource
    private CarInfoDao carInfoDao;
    @Resource
    private ChauffeurTakecarDao chauffeurTakecarDao;
    @Resource
    private ChauffeurContractDao chauffeurContractDao;
    @Resource
    private AttachmentService attachmentService;
    @Resource
    private ChauffeurWorkDao chauffeurWorkDao;
    @Resource
    private ChauffeurFamilyDao chauffeurFamilyDao;
    @Resource
    private ChauffeurBondsmanDao bondsmanDao;
    @Resource
    private ChauffeurApplyMonthDao applyMonthDao;
    @Resource
    private CarHirePackageMonthDao hirePackageMonthDao;
    @Resource
    private ChauffeurSnapshotDao chauffeurSnapshotDao;
    @Resource
    private ChauffeurDao chauffeurDao;
    @Resource
    private ChauffeurApplyMonthService applyMonthService;
    @Resource
    private ChauffeurApplyService chauffeurApplyService;
    @Resource
    private CarBrandDao brandDao;
    @Resource
    private CarInfoService carInfoService;
    @Resource
    private ChauffeurContractService contractService;
    @Resource
    private ChauffeurFeeService feeService;
    @Resource
    private ChauffeurFeeDao feeDao;
    @Resource
    private NotifyService notifyService;
    @Resource
    private CarHirePackageDao carHirePackageDao;
    @Resource
    private CarInfoAssetsService assetsService;
    @Resource
    UserDao userDao;
    @Resource
    private SaleCommissionService commissionService;
    @Resource
    private ChauffeurApplyWarningService applyWarningService;
    @Resource
    private ChauffeurHireFeeListService chauffeurHireFeeListService;

    @Resource
    private CarAccessAreaDao carAccessAreaDao;

    @Resource
    private ChauffeurService chauffeurService;
    @Resource
    private CarChauffeurContractV2Service carChauffeurContractV2Service;
    @Resource
    private CarChauffeurOnceFeeDao carChauffeurOnceFeeDao;
    @Resource
    private SysIncService sysIncService;
    @Resource
    private FeelistDao feelistDao;

    @Resource
    private CompanyDao companyDao;
    @Resource
    private ChauffeurHireFeeListBasicDao chauffeurHireFeeListBasicDao;

    @Resource
    private ChauffeurHireFeeListPeriodDao chauffeurHireFeeListPeriodDao;

    @Resource
    CarInfoAggrProcessService carInfoAggrProcessService;
    @Autowired
    private DcarBaseCustomerService dcarBaseCustomerService;


    @Resource
    private SysUseErrorAggrInfoService sysUseErrorAggrInfoService;

    @Resource
    private CarChauffeurAduitDateDao carChauffeurAduitDateDao;
    
    @Resource
    private CarChauffeurAduitDateService carChauffeurAduitDateService;

    @Resource
    private CarChauffeurHirePoundageFeeDao hirePoundageFeeDao;
    @Resource
    private ChauffeurApplyWarningService chauffeurApplyWarningService;
    
    @Resource
    private CarChauffeurOnceFeeDetailDao carChauffeurOnceFeeDetailDao;
    @Resource
    private CompanyService companyService;
    
    @Resource
	SysExceptionDao sysExceptionDao;
    
    @Resource
	SysExceptionService sysExceptionService;
    
    @Resource
    ChauffeurHireFeePayHistoryRecordDao chauffeurHireFeePayHistoryRecordDao;
    
    @Resource
    private BbuninessesHisService bbuninessesHisService;


    @Resource
    private CarReorganizeService carReorganizeService;

    public ChauffeurDetail get(Long id) {
        return super.get(id);
    }

    public ChauffeurDetail getAll(Long id) {
        ChauffeurDetail chauffeurDetail = super.get(id);
        if (chauffeurDetail == null) {
            return null;
        }
        //1.获取风控评级
        ChauffeurRiskCtl chauffeurRisk = chauffeurRiskCtlDao.getByChauffeurId(chauffeurDetail.getChauffeurId());
        if (chauffeurRisk == null) {
            chauffeurRisk = new ChauffeurRiskCtl();
            chauffeurRisk.setChauffeurId(chauffeurDetail.getChauffeurId());
        }
        chauffeurDetail.setChauffeurRiskCtl(chauffeurRisk);
        //2.获取审核申请
        ChauffeurApply chauffeurApply = chauffeurApplyDao.getByChauffeurId(chauffeurDetail.getChauffeurId());
        chauffeurDetail.setChauffeurApply(chauffeurApply);
        //租车申请,月租租金
        if (chauffeurApply != null && chauffeurApply.getId() != null) {
            List<ChauffeurApplyMonth> applyMonths = applyMonthDao.findListByApplyId(chauffeurApply.getId());
            chauffeurApply.setApplyMonths(applyMonths);
            ;
        }
        if (chauffeurApply != null && chauffeurApply.getRemarks() != null) {
            String htmlUnescape = HtmlUtils.htmlUnescape(chauffeurApply.getRemarks());
            if (htmlUnescape != null) {
                htmlUnescape = htmlUnescape.replaceAll("\"", "'");
                htmlUnescape = htmlUnescape.replaceAll("\r", "");
                htmlUnescape = htmlUnescape.replaceAll("\n", "");
                htmlUnescape = htmlUnescape.replaceAll(" +", " ");
            }
            chauffeurApply.setRemarks(htmlUnescape);
        }

        //3.获取工作经历
        chauffeurDetail.setWorks(chauffeurWorkService.findByChauffeurId(chauffeurDetail.getChauffeurId()));
        //4.家庭成员
        chauffeurDetail.setFamilies(chauffeurFamilyService.findByChauffeurId(chauffeurDetail.getChauffeurId()));
        //5.客户合同
        chauffeurDetail.setChauffeurContract(chauffeurContractDao.getByChauffeurId(chauffeurDetail.getChauffeurId()));
        //6.提车记录
        chauffeurDetail.setChauffeurTakecar(chauffeurTakecarDao.getByChauffeurId(chauffeurDetail.getChauffeurId()));
        //7.担保人
        chauffeurDetail.setChauffeurBondsman(bondsmanDao.getBychauffeurId(chauffeurDetail.getChauffeurId()));
        //8.审核过程
        ChauffeurProcess chauffeurProcess = new ChauffeurProcess();
        Page<ChauffeurProcess> proPage = new Page<ChauffeurProcess>();
        proPage.setOrderBy("a.create_date desc , a.pre_status desc ");
        chauffeurProcess.setPage(proPage);
        chauffeurProcess.setChauffeurId(chauffeurDetail.getChauffeurId());
        List<ChauffeurProcess> processList = chauffeurProcessDao.findList(chauffeurProcess);
        if (processList == null || processList.size() >= 0) {
            for (ChauffeurProcess proecss : processList) {
                proecss.setCurrStaLabel(DictUtils.getDictLabel(proecss.getCurrStatus() + "", "chauffeur_status", ""));
                proecss.setPreStaLabel(DictUtils.getDictLabel(proecss.getPreStatus() + "", "chauffeur_status", ""));
                String htmlUnescape = HtmlUtils.htmlUnescape(proecss.getRemarks());
                proecss.setRemarks(htmlUnescape);
            }
        }
        chauffeurDetail.setProcesses(processList);
        return chauffeurDetail;
    }

    public ChauffeurDetail getByChauffeurIdAll(Long chauffeurId) {
        // return chauffeurDetailDao.getByChauffeurId(chauffeurId);

        ChauffeurDetail chauffeurDetail = chauffeurDetailDao.getByChauffeurId(chauffeurId);
        if (chauffeurDetail == null) {
            return null;
        }


        //1.获取风控评级
        ChauffeurRiskCtl chauffeurRisk = chauffeurRiskCtlDao.getByChauffeurId(chauffeurDetail.getChauffeurId());
//          if (chauffeurRisk == null) {
//              chauffeurRisk = new ChauffeurRiskCtl();
//              chauffeurRisk.setChauffeurId(chauffeurDetail.getChauffeurId());
//          }
        if (chauffeurRisk != null) {
            chauffeurDetail.setChauffeurRiskCtl(chauffeurRisk);

        }
        //2.获取审核申请
        ChauffeurApply chauffeurApply = chauffeurApplyDao.getByChauffeurId(chauffeurDetail.getChauffeurId());
//          System.out.println(chauffeurApply.getName());
//          System.out.println(chauffeurApply.getAnnexedArea());
        chauffeurDetail.setChauffeurApply(chauffeurApply);

        //租车申请,月租租金
        if (chauffeurApply != null && chauffeurApply.getId() != null) {
            List<ChauffeurApplyMonth> applyMonths = applyMonthDao.findListByApplyId(chauffeurApply.getId());
            chauffeurApply.setApplyMonths(applyMonths);
            ;
        }
        if (chauffeurApply != null && chauffeurApply.getRemarks() != null) {
            String htmlUnescape = HtmlUtils.htmlUnescape(chauffeurApply.getRemarks());
            if (htmlUnescape != null) {
                htmlUnescape = htmlUnescape.replaceAll("\"", "'");
                htmlUnescape = htmlUnescape.replaceAll("\r", "");
                htmlUnescape = htmlUnescape.replaceAll("\n", "");
                htmlUnescape = htmlUnescape.replaceAll(" +", " ");
            }
            chauffeurApply.setRemarks(htmlUnescape);
        }

        //3.获取工作经历
        chauffeurDetail.setWorks(chauffeurWorkService.findByChauffeurId(chauffeurDetail.getChauffeurId()));
        //4.家庭成员
        chauffeurDetail.setFamilies(chauffeurFamilyService.findByChauffeurId(chauffeurDetail.getChauffeurId()));
        //5.客户合同
        chauffeurDetail.setChauffeurContract(chauffeurContractDao.getByChauffeurId(chauffeurDetail.getChauffeurId()));
        //6.提车记录
        chauffeurDetail.setChauffeurTakecar(chauffeurTakecarDao.getByChauffeurId(chauffeurDetail.getChauffeurId()));
        //7.担保人
        chauffeurDetail.setChauffeurBondsman(bondsmanDao.getBychauffeurId(chauffeurDetail.getChauffeurId()));
        //8.审核过程
        ChauffeurProcess chauffeurProcess = new ChauffeurProcess();
        Page<ChauffeurProcess> proPage = new Page<ChauffeurProcess>();
        proPage.setOrderBy("a.create_date desc , a.pre_status desc ");
        chauffeurProcess.setPage(proPage);
        chauffeurProcess.setChauffeurId(chauffeurDetail.getChauffeurId());
        List<ChauffeurProcess> processList = chauffeurProcessDao.findList(chauffeurProcess);
        if (processList == null || processList.size() >= 0) {
            for (ChauffeurProcess proecss : processList) {
                proecss.setCurrStaLabel(DictUtils.getDictLabel(proecss.getCurrStatus() + "", "chauffeur_status", ""));
                proecss.setPreStaLabel(DictUtils.getDictLabel(proecss.getPreStatus() + "", "chauffeur_status", ""));
                String htmlUnescape = HtmlUtils.htmlUnescape(proecss.getRemarks());
                proecss.setRemarks(htmlUnescape);
            }
        }
        chauffeurDetail.setProcesses(processList);

        //专架公司
        if (chauffeurDetail.getCompanyId() != null) {
            chauffeurDetail.setCompany(companyDao.get(Long.valueOf(chauffeurDetail.getCompanyId())));
        }
        if (chauffeurDetail.getHireCompany() != null && chauffeurDetail.getHireCompany().getId() != null) {
            chauffeurDetail.setHireCompany(companyDao.get(Long.valueOf(chauffeurDetail.getHireCompany().getId())));

        }

        return chauffeurDetail;
    }


    public ChauffeurDetail getAllByChauffeurId(Long chauffeurId) {
        ChauffeurDetail detail = dao.getByChauffeurId(chauffeurId);
        ChauffeurDetail db = null;
        if (detail != null && detail.getId() != null) {
            db = getAll(detail.getId());
        }

        return db;
    }

    public List<ChauffeurDetail> findList(ChauffeurDetail chauffeurDetail) {
        return super.findList(chauffeurDetail);
    }

    public Page<ChauffeurDetail> findPage(Page<ChauffeurDetail> page, ChauffeurDetail chauffeurDetail) {
        return super.findPage(page, chauffeurDetail);
    }

    public Page<ChauffeurDetail> findPage(Page<ChauffeurDetail> page, ChauffeurDetail chauffeurDetail, String orderKey, String orderValue) {
        if (!StringUtils.isBlank(orderValue) && !StringUtils.isBlank(orderKey)) {

            if (orderValue.equals("asc") || orderValue.equals("desc")) {
                String setOrder = orderKey + " " + orderValue;
                page.setOrderBy(setOrder);
            }
        }

        return super.findPage(page, chauffeurDetail);
    }

    public Page<ChauffeurDetail> findVideoList(Page<ChauffeurDetail> page, ChauffeurDetail chauffeurDetail) {
        chauffeurDetail.setPage(page);
        page.setList(dao.findVideoList(chauffeurDetail));
        return page;
    }

    /**
     * @param @param chauffeurDetail
     * @param @param pre_chauffeurDetail
     * @return void
     * @Title: update
     * @Description: 修改客户资料
     */

    @Transactional(readOnly = false)
    public void update(ChauffeurDetail chauffeurDetail, ChauffeurDetail pre_chauffeurDetail, Long packageId, String isSave) {
        //1.设置客户的状态
        if (!isSave.equals("true")) {
            setStatus(chauffeurDetail);
            chauffeurDetail.setDetailModifyDate(new Date());
        }
        CarHirePackage carHirePackage = carHirePackageDao.getRelById(packageId);
        if (carHirePackage != null) {
            chauffeurDetail.setCarInfoType(carHirePackage.getCarInfoType());
        }
        //2.保存基础详情信息
        super.save(chauffeurDetail);
        //2.删除工作经历
        chauffeurWorkDao.deleteByChauffeurId(chauffeurDetail.getChauffeurId());
        ;
        //3.保存客户的工作信息
        chauffeurWorkService.saveAll(chauffeurDetail);
        //4.删除家庭成员
        chauffeurFamilyDao.deleteByChauffeurId(chauffeurDetail.getChauffeurId());
        //5.保存客户的家庭信息
        chauffeurFamilyService.saveAll(chauffeurDetail);
        //7.保存客户的套餐信息
        if (chauffeurDetail.getChauffeurApply() != null && chauffeurDetail.getChauffeurApply().getId() != null) {
            ChauffeurApply chauffeurApply = chauffeurDetail.getChauffeurApply();
            //封装车辆套餐
            chauffeurApply = chauffeurApplyService.setCarHirePackage(chauffeurDetail, chauffeurApply, packageId);
            //保存历史记录
            ChauffeurApply apply = chauffeurApplyDao.getAreaById(chauffeurApply.getId());
            //是否更改套餐
            if (apply != null && (!apply.getName().equals(chauffeurApply.getName()))) {
                chauffeurApply.setStatus(apply.getStatus());
                apply.setStatus(0);
                apply.setId(null);
                chauffeurApplyDao.insert(apply);
            }
            chauffeurApply.setStatus(ChauffeurConstants.APPLY_STATUS_VALID);
            //保存车辆套餐
            chauffeurApplyService.save(chauffeurApply);
            ;
            //保存套餐月份租金
            applyMonthService.saveApplyMonths(chauffeurApply, packageId, chauffeurDetail);
        }
        //6.保存附件
        attaUploadForm(chauffeurDetail);
        //7保存当保人
        saveBondsman(chauffeurDetail);
        //7.修改调整的过程
        String remarks = getRemarks(chauffeurDetail, pre_chauffeurDetail);
        chauffeurProcessService.save(chauffeurDetail, pre_chauffeurDetail.getStatus(), "修改   " + remarks, "");
        //保存数据快照
        saveSnapshot(pre_chauffeurDetail);
        notifyService.notify(chauffeurDetail);
    }

    private void setStatus(ChauffeurDetail chauffeurDetail) {
        //有风控结果,和状态是待调整的
        if (chauffeurDetail.getRiskAuditResult() != null) {
            /*&& (
                    chauffeurDetail.getStatus().equals(ChauffeurStatus.DATA_PENDING_ADJUSTED.getValue()) ||
					chauffeurDetail.getStatus().equals(ChauffeurStatus.BACK_PENDING_ADJUSTED.getValue()) ) || 
					chauffeurDetail.getStatus().equals(ChauffeurStatus.MANAGE_BACK_PENDING_ADJUSTED.getValue())*/
            //拒绝打回
            if (chauffeurDetail.getStatus().equals(ChauffeurStatus.MANAGE_PENDING_ADJUSTED.getValue())) {
                chauffeurDetail.setStatus(ChauffeurStatus.REFUSAL_DATA_ADJUSTED.getValue());
                chauffeurDetail.setRiskModifyDate(new Date());
            } else
                //拒绝打回
                if (chauffeurDetail.getStatus().equals(ChauffeurStatus.MANAGE_BACK_PENDING_ADJUSTED.getValue())) {
                    chauffeurDetail.setStatus(ChauffeurStatus.STAY_MANAGE.getValue());
                    chauffeurDetail.setRiskModifyDate(new Date());
                } else
                    //风控人员不通过
                    if (chauffeurDetail.getRiskAuditResult().equals(Integer.parseInt(RiskRate.CONDITION_PSS.getValue()))) {
                        chauffeurDetail.setStatus(ChauffeurStatus.DATA_PASS.getValue());
                        chauffeurDetail.setRiskModifyDate(new Date());
                        applyWarningService.updateCoordinate(chauffeurDetail);
                    } else {
                        //资料审核不通过
                        chauffeurDetail.setStatus(ChauffeurStatus.DATA_UNDERWAY.getValue());
                    }
        } else {
            //资料审核不通过
            chauffeurDetail.setStatus(ChauffeurStatus.DATA_UNDERWAY.getValue());
        }
    }


    /**
     * @param @param chauffeurDetail
     * @Title: saveBondsman
     * @Description: 保存当保人
     */
    public void saveBondsman(ChauffeurDetail chauffeurDetail) {
        //保存客户当保人
        ChauffeurBondsman bondsman = chauffeurDetail.getChauffeurBondsman();

        if (bondsman != null) {
            User user = chauffeurDetail.getUpdateBy();
            if (bondsman.getId() != null) {
                bondsman.setChauffeurId(chauffeurDetail.getChauffeurId());
                bondsman.setUpdateBy(user);
                bondsman.setUpdateDate(new Date());
                bondsman.setRemarks("");
                bondsmanDao.update(bondsman);
            } else {
                bondsman.setChauffeurId(chauffeurDetail.getChauffeurId());
                bondsman.setCreateBy(user);
                bondsman.setCreateDate(new Date());
                bondsman.setRemarks("");
                bondsmanDao.insert(bondsman);
            }
        }
    }


    @Transactional(readOnly = false)
    public void delete(ChauffeurDetail chauffeurDetail) {
        super.delete(chauffeurDetail);
    }

    public ChauffeurDetail getByMobilePhone(String mobilePhone) {
        return chauffeurDetailDao.getByMobilePhone(mobilePhone);
    }

    public ChauffeurDetail getByIdcardNo(String idcardNo) {
        return chauffeurDetailDao.getByIdcardNo(idcardNo);
    }

    public ChauffeurDetail getByChauffeurId(Long chauffeurId) {
        return chauffeurDetailDao.getByChauffeurId(chauffeurId);
    }

    public ChauffeurDetail getByNameAndCarNo(String name, String carNo) {
        ChauffeurDetail detail = new ChauffeurDetail();
        detail.setName(name);
        detail.setCarNo(carNo);
        return chauffeurDetailDao.getByNameAndCarNo(detail);
    }

    @Transactional(readOnly = false)
    public void print(ChauffeurDetail detail) {
        Integer preStatus = detail.getStatus();
        detail.setStatus(ChauffeurStatus.NOTICE.getValue());
        detail.setPrintInformDate(new Date());
        detail.setContractNo(ChauffeurUtils.generateContractNo(detail));
        //添加过程
        chauffeurProcessService.save(detail, preStatus, "打印通知单", "");
        if (preStatus.equals(ChauffeurStatus.RISK_PASS.getValue())) {
            chauffeurDetailDao.updatePrintInfo(detail);
        }
        notifyService.notify(detail);
    }

    @Transactional(readOnly = false)
    public void printContract(ChauffeurDetail chauffeurDetail) {
        Integer preStatus = chauffeurDetail.getStatus();
        chauffeurDetail.setStatus(ChauffeurStatus.CONTRACT.getValue());
        chauffeurDetail.setSignContractDate(new Date());
        chauffeurProcessService.save(chauffeurDetail, preStatus, "打印合同", "");

        if (preStatus.equals(ChauffeurStatus.DEPOSIT.getValue())) {
            this.save(chauffeurDetail);
        }
    }

    public Page<ChauffeurDetail> findPageForRisk(Page<ChauffeurDetail> page, ChauffeurDetail entity, String orderKey, String orderValue) {
        if (!StringUtils.isBlank(orderValue) && !StringUtils.isBlank(orderKey)) {
            if (orderValue.equals("asc") || orderValue.equals("desc")) {
                String setOrder = orderKey + " " + orderValue;
                page.setOrderBy(setOrder);
            }
        }
        entity.setPage(page);
        page.setList(chauffeurDetailDao.findListForRisk(entity));
        return page;
    }


    @Transactional(readOnly = false)
    public void updateStatus(ChauffeurDetail chauffeurDetail, Integer status, String remarks) {
        Integer preStatus = chauffeurDetail.getStatus();
        chauffeurDetail.setUpdateBy(UserUtils.getUser());
        chauffeurDetail.setUpdateDate(new Date());
        chauffeurDetail.setStatus(status);
        chauffeurDetailDao.updateChauStatus(chauffeurDetail);
        //5.保存申请记录
        chauffeurProcessService.save(chauffeurDetail, preStatus, remarks, "");
    }

    /**
     * @param @param  chauffeurDetail
     * @param @param  pre_chauffeurDetail
     * @param @return
     * @return String
     * @Title: getRemarks
     * @Description: 获取比较内容,差别备注
     */
    private String getRemarks(ChauffeurDetail chauffeurDetail, ChauffeurDetail pre_chauffeurDetail) {
        StringBuffer remarks = new StringBuffer();
        if (chauffeurDetail == null || pre_chauffeurDetail == null || pre_chauffeurDetail.getChauffeurApply() == null) {
            return remarks.toString();
        }
        //1.比较申请
        if (chauffeurDetail.getChauffeurApply() != null && pre_chauffeurDetail.getChauffeurApply() != null) {
            ChauffeurApply apply = chauffeurDetail.getChauffeurApply();
            ChauffeurApply pre_apply = pre_chauffeurDetail.getChauffeurApply();
            //套餐名
            if (!apply.getName().equals(pre_apply.getName())) {
                remarks.append(getText("套餐名", pre_apply.getName(), apply.getName()));
            }

        }
        return remarks.toString();
    }

    private String getText(String name, String pre_value, String new_value) {
        return name + ":【" + pre_value + "】修改为【" + new_value + "】,";
    }


    /**
     * @param @param  takecarInfo
     * @param @param  apply
     * @param @param  chauffeurDetail
     * @param @return
     * @return String
     * @Title: takecar
     * @Description: 提车
     */
    @Transactional
    public String takecar(ChauffeurTakecar takecarInfo, ChauffeurApply apply, ChauffeurDetail chauffeurDetail) {
        //1.验证车牌号
        CarInfo carInfo = null;
        if (StringUtils.isBlank(takecarInfo.getCarNo())) {
            CarInfo info = new CarInfo();
            info.setFrameNo(takecarInfo.getFrameNo());
            carInfo = carInfoDao.getByFrameNo(info);
        } else {
            carInfo = carInfoDao.findByCarNo(takecarInfo.getCarNo());
        }

        if (carInfo == null) {
            return "该车牌不存在";
        }
        if (carInfo.getChauffeurId() != 0l) {
            return "该车牌号已租出";
        }
        if(carInfo.getStatus()==2){
            return "该车已经出库";
        }
        CarReorganize byCarNo = carReorganizeService.getByCarNo(carInfo.getCarNo());
        if(byCarNo!=null &&  byCarNo.getStatus()!=30 && byCarNo.getStatus()!=90){
            return "该车辆已提交整备";
        }

        if (chauffeurDetail == null || chauffeurDetail.getSalesman() == null) {
            return "没有销售人员";
        }
        User saleman = chauffeurDetail.getSalesman();
        saleman = UserUtils.get(saleman.getId());
        takecarInfo.setSalesmanId(chauffeurDetail.getSalesman().getId());
        Office office = saleman.getOffice();
        if (office == null) {
            return "没有销售人员所在的机构";
        }
        User saleManager = null;//销售经理
        if (office != null && office.getPrimaryPerson() != null) {
            saleManager = office.getPrimaryPerson();
        }
        if (saleManager == null) {
            return "没有销售经理";
        }
        takecarInfo.setSalesManagerId(saleManager.getId());
        takecarInfo.setFrameNo(carInfo.getFrameNo());
        //2.保存提车记录
        takecarInfo.setContractStatus(0);
        takecarInfo.setContractNo(chauffeurDetail.getContractNo());
        //takecarInfo.setHireRental(apply.getHireRental());
        //takecarService.save(takecarInfo);
        if (takecarInfo.getIsNewRecord()) {
            if(UserContextHolder.getCurrentUser()!=null && UserContextHolder.getCurrentUser().getId()!=null){
                takecarInfo.preInsert();
            }
            try {
                chauffeurTakecarDao.insert(takecarInfo);
            }catch (Exception e){
                logger.error("数据库保存异常:"+e.getMessage(),e);
                return "数据库保存异常";
            }

        } else {
            takecarInfo.preUpdate();
            chauffeurTakecarDao.update(takecarInfo);
        }

        Integer preStatus = chauffeurDetail.getStatus();

        //3.修改提车状态
        chauffeurDetail.setStatus(ChauffeurStatus.TAKE_CAR.getValue());
        if (chauffeurDetail.getTakeCarDate() == null) {
            chauffeurDetail.setTakeCarDate(new Date());
        }
        chauffeurDetail.setCarNo(takecarInfo.getCarNo());
        chauffeurDetail.setUpdateDate(new Date());
        if(UserUtils.getUser()!=null && UserUtils.getUser().getId()!=null && UserUtils.getUser().getId()!=0l){
            chauffeurDetail.setUpdateBy(UserUtils.getUser());
        }
        chauffeurDetailDao.updateTakeCarInfo(chauffeurDetail);

        //4.修改车的使用者
        carInfo.setChauffeurId(takecarInfo.getChauffeurId());
        carInfo.setChauffeurName(chauffeurDetail.getName());
        carInfoDao.updateChaufferByCarNo(carInfo);
        //5.保存申请记录
        chauffeurProcessService.save(chauffeurDetail, preStatus, "提车-" + takecarInfo.getRemarks(), "");
        notifyService.notify(chauffeurDetail);

        //6.增加提成记录
        commissionService.saveSaleCommission(chauffeurDetail, takecarInfo);

        carInfoAggrProcessService.saveByDetail(chauffeurDetail,
                CarInfoAggrProcessStatus.STATUS_30.getValue(),
                CarInfoAggrProcessStatus.STATUS_70.getValue(), takecarInfo.getRemarks());

        return "true";
    }

    /**
     * @param @param  takecarInfo
     * @param @param  apply
     * @param @param  chauffeurDetail
     * @param @return
     * @return String
     * @Title: takecar
     * @Description: 提车
     */
    public String takecar_Import(ChauffeurTakecar takecarInfo, ChauffeurApply apply
            , ChauffeurDetail chauffeurDetail, CarInfo cx) {

        cx.setChauffeurId(chauffeurDetail.getChauffeurId());
        cx.setChauffeurName(chauffeurDetail.getName());
        carInfoDao.updateChaufferByCarNo(cx);//更新车辆所属客户

        //takecarService.save(takecarInfo);//保存提车记录
        if (takecarInfo.getIsNewRecord()) {
            takecarInfo.preInsert();
            chauffeurTakecarDao.insert(takecarInfo);
        } else {
            takecarInfo.preUpdate();
            chauffeurTakecarDao.update(takecarInfo);
        }
        switch("ss"){
            case "ss":
            case "aa":

        }

        Integer preStatus = chauffeurDetail.getStatus();

        //3.修改提车状态
        chauffeurDetail.setStatus(ChauffeurStatus.TAKE_CAR.getValue());
        if (chauffeurDetail.getTakeCarDate() == null) {
            chauffeurDetail.setTakeCarDate(new Date());
        }
        chauffeurDetail.setContractNo(takecarInfo.getContractNo());
        chauffeurDetail.setCarNo(takecarInfo.getCarNo());
        chauffeurDetailDao.updateTakeCarInfo(chauffeurDetail);

        //5.保存申请记录
        chauffeurProcessService.save(chauffeurDetail, preStatus, "提车-" + takecarInfo.getRemarks(), "");


//		//6.增加提成记录
//		commissionService.saveSaleCommission(chauffeurDetail,takecarInfo);
        return "true";
    }

    /**
     * @param @param  chauffeurDetail
     * @param @return
     * @return ChauffeurApply
     * @Title: updateApply
     * @Description:审核
     */
    @Transactional(readOnly = false)
    public ChauffeurApply updateApply(ChauffeurDetail chauffeurDetail) {

        if (chauffeurDetail.getChauffeurApply() != null && chauffeurDetail.getChauffeurApply().getId() != null) {
            //1.比较修改内容
            ChauffeurApply chauffeurApply = chauffeurDetail.getChauffeurApply();
            ChauffeurDetail pre_chauffeurDetail = new ChauffeurDetail();
            pre_chauffeurDetail.setChauffeurApply(chauffeurApply);
            String remarks = getRemarks(chauffeurDetail, pre_chauffeurDetail);
            //2.保存审核申请
            chauffeurApply.setUpdateBy(chauffeurDetail.getUpdateBy());
            ChauffeurApply apply = chauffeurApplyDao.get(chauffeurApply.getId());
            apply.setStatus(0);
            apply.setId(null);
            //保存上个审核记录
            chauffeurApplyDao.insert(apply);
            chauffeurApply.setUpdateDate(new Date());
            ;
            //修改当前记录
            chauffeurApplyDao.updateApplyInfo(chauffeurApply);
            //3.保存申请过程
            String dictLabel = DictUtils.getDictLabel(chauffeurDetail.getStatus() + "", "chauffeur_status", "");
            chauffeurProcessService.save(chauffeurDetail, chauffeurDetail.getStatus(), "【" + dictLabel + "】" + remarks, "");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-M-dd HH:mm:ss");
            apply.setRemarks(dateFormat.format(apply.getUpdateDate()));
            return apply;
        }
        return null;

    }


    @Transactional(readOnly = false)
    public void confirmDeposit(ChauffeurDetail chauffeurDetail, String remarks) {
        Integer preStatus = chauffeurDetail.getStatus();
        chauffeurDetail.setStatus(ChauffeurStatus.DEPOSIT.getValue());
        chauffeurDetail.setReceiveDepositDate(new Date());
        chauffeurDetailDao.updateDepositInfo(chauffeurDetail);
        chauffeurProcessService.save(chauffeurDetail, preStatus, "车辆保证金确认:" + remarks, "");
        notifyService.notify(chauffeurDetail);
    }

    public Page<ChauffeurDetail> auditList(Page<ChauffeurDetail> page, ChauffeurDetail chauffeurDetail, String orderKey, String orderValue) {
        if (!StringUtils.isBlank(orderValue) && !StringUtils.isBlank(orderKey)) {

            if (orderValue.equals("asc") || orderValue.equals("desc")) {
                String setOrder = orderKey + " " + orderValue;
                page.setOrderBy(setOrder);
            }
        }
        chauffeurDetail.setPage(page);
        page.setList(chauffeurDetailDao.auditList(chauffeurDetail));
        return page;
    }


    private String statusAlias = "status";
    private String totalAlias = "total";

    /**
     * 获取待办数
     */
    public Map<String, Integer> getPendings() {
        Map<String, Integer> result = initResult();
        List<Map<String, Object>> pendings = chauffeurDetailDao.getPendings();
        for (Map<String, Object> pending : pendings) {
            if (pending.get(statusAlias).equals(ChauffeurStatus.DATA_UNDERWAY.getValue())) {
                result.put(ChauffeurStatus.DATA_UNDERWAY.name(),
                        result.get(ChauffeurStatus.DATA_UNDERWAY.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.DATA_NO_PASS.getValue())
                    || pending.get(statusAlias).equals(ChauffeurStatus.DATA_PENDING_ADJUSTED.getValue())) {
                result.put(ChauffeurStatus.DATA_PENDING_ADJUSTED.name(),
                        result.get(ChauffeurStatus.DATA_PENDING_ADJUSTED.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.DATA_PASS.getValue())
                    || pending.get(statusAlias).equals(ChauffeurStatus.DATA_ADJUSTED.getValue())
                    || pending.get(statusAlias).equals(ChauffeurStatus.ATTACHE_AUDIT.getValue())) {
                result.put(ChauffeurStatus.DATA_PASS.name(),
                        result.get(ChauffeurStatus.DATA_PASS.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.STAY_MANAGE.getValue())) {
                result.put(ChauffeurStatus.STAY_MANAGE.name(),
                        result.get(ChauffeurStatus.STAY_MANAGE.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.RISK_PASS.getValue())) {
                result.put(ChauffeurStatus.RISK_PASS.name(),
                        result.get(ChauffeurStatus.RISK_PASS.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.NOTICE.getValue())) {
                result.put(ChauffeurStatus.NOTICE.name(),
                        result.get(ChauffeurStatus.NOTICE.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.DEPOSIT.getValue())) {
                result.put(ChauffeurStatus.DEPOSIT.name(),
                        result.get(ChauffeurStatus.DEPOSIT.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.CONTRACT.getValue())) {
                result.put(ChauffeurStatus.CONTRACT.name(),
                        result.get(ChauffeurStatus.CONTRACT.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.TAKE_CAR.getValue())) {
                result.put(ChauffeurStatus.TAKE_CAR.name(),
                        result.get(ChauffeurStatus.TAKE_CAR.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.VIDEO_PASS.getValue())) {
                result.put(ChauffeurStatus.VIDEO_PASS.name(),
                        result.get(ChauffeurStatus.VIDEO_PASS.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            } else if (pending.get(statusAlias).equals(ChauffeurStatus.STOCK.getValue())) {
                result.put(ChauffeurStatus.STOCK.name(),
                        result.get(ChauffeurStatus.STOCK.name()) + Integer.parseInt(pending.get(totalAlias).toString()));
            }

        }
        return result;
    }

    /**
     * 数据初始化为0
     *
     * @return
     */
    private Map<String, Integer> initResult() {
        Map<String, Integer> result = new HashMap<String, Integer>();
        result.put(ChauffeurStatus.DATA_UNDERWAY.name(), 0);
        result.put(ChauffeurStatus.DATA_PENDING_ADJUSTED.name(), 0);
        result.put(ChauffeurStatus.DATA_PASS.name(), 0);
        result.put(ChauffeurStatus.STAY_MANAGE.name(), 0);
        result.put(ChauffeurStatus.RISK_PASS.name(), 0);
        result.put(ChauffeurStatus.NOTICE.name(), 0);
        result.put(ChauffeurStatus.DEPOSIT.name(), 0);
        result.put(ChauffeurStatus.CONTRACT.name(), 0);
        result.put(ChauffeurStatus.TAKE_CAR.name(), 0);
        result.put(ChauffeurStatus.VIDEO_PASS.name(), 0);
        result.put(ChauffeurStatus.STOCK.name(), 0);

        return result;
    }

    /**
     * 保存数据快照
     *
     * @param pre_chauffeurDetail
     * @return
     */
    private ChauffeurSnapshot saveSnapshot(ChauffeurDetail pre_chauffeurDetail) {
        ChauffeurSnapshot snapshot = null;
        if (pre_chauffeurDetail != null) {

            snapshot = new ChauffeurSnapshot();
            snapshot.setChauffeurId(pre_chauffeurDetail.getChauffeurId());
            String json = JsonUtils.toJSon(pre_chauffeurDetail);
            snapshot.setDataSnapshot(json);
            snapshot.preInsert();
            chauffeurSnapshotDao.insert(snapshot);
        }
        return snapshot;
    }

    /**
     * @param @param chauffeurDetail
     * @return void
     * @Title: inputDetail
     * @Description: 录入客户资料
     */
    @Transactional(readOnly = false)
    public void inputDetail(ChauffeurDetail chauffeurDetail, Long packageId, boolean isChangeStatus) {
        if (chauffeurDetail.getChauffeurId() == null || chauffeurDetail.getChauffeurId() == 0l) {
            chauffeurService.newReg(chauffeurDetail);
            chauffeurDetail.setContractNo(ChauffeurUtils.generateContractNo(chauffeurDetail));
        }

        if (chauffeurDetail.getApplyNo() == null || chauffeurDetail.getApplyNo().trim().equals("")) {
            String city = chauffeurDetail.getCity();
            String cityPinYin = com.ihavecar.hirecar.common.utils.StringUtils.getCityInit(city);
            String dateFormat = DateFormatUtils.format(chauffeurDetail.getCreateDate(), "yyyyMMdd");
            chauffeurDetail.setApplyNo(cityPinYin + sysIncService.generate(dateFormat, 3, SysInc.SysIncType.TYPE_12));
        }
        ChauffeurDetail pre_chauffeurDetail=null;
        if (chauffeurDetail.getId() != null) {
            //获取历史
            pre_chauffeurDetail = getAll(chauffeurDetail.getId());
            //保存数据快照
            //saveSnapshot(pre_chauffeurDetail);
        }

        Integer preStatus = chauffeurDetail.getStatus();
        String remarks = "客户录入:";
        if (isChangeStatus) {
           /* if(!preStatus.equals(ChauffeurStatusV2.BACK_FOR_ADJUST.getValue())){
                chauffeurDetail.setStatus(ChauffeurStatusV2.WAIT_FOR_SUBMISSION.getValue());
            }*/
            chauffeurDetail.setDetailSubmitDate(new Date());
            remarks += "录入";
        } else {
            remarks += "保存";
        }
        chauffeurDetail.setUpdateDate(new Date());
        if (UserUtils.getUser() != null && UserUtils.getUser().getId() != null) {
            chauffeurDetail.setUpdateBy(UserUtils.getUser());
        }
        chauffeurDetail.setBusinessArea(chauffeurDetail.getChauffeurApply().getBusinessArea());
        CarHirePackage carHirePackage = carHirePackageDao.getRelById(chauffeurDetail.getChauffeurApply().getBrandId());
        if (carHirePackage != null) {
            chauffeurDetail.setCarInfoType(carHirePackage.getCarInfoType());
        }
        //保存
        dao.inputDetail(chauffeurDetail);
        try {
            applyWarningService.saveEsWarningData(chauffeurDetail);
        }catch (Exception e){
           // e.printStackTrace();
            logger.error("es客户数据同步失败",e);
        }
        ChauffeurApply chauffeurApply = chauffeurDetail.getChauffeurApply();
        //1.保存审核
        if (chauffeurApply != null) {
            //封装车辆套餐
            chauffeurApply = chauffeurApplyService.setCarHirePackage(chauffeurDetail, chauffeurApply, packageId);
            chauffeurApply.setChauffeurId(chauffeurDetail.getChauffeurId());
            chauffeurApply.setCreateBy(chauffeurDetail.getUpdateBy());
            chauffeurApply.setUpdateBy(chauffeurDetail.getUpdateBy());
            chauffeurApply.setCreateDate(new Date());
            chauffeurApply.setUpdateDate(new Date());
            chauffeurApply.setStatus(1);
            //保存历史记录
            ChauffeurApply apply = chauffeurApplyDao.getRelByChauffeurId(chauffeurDetail.getChauffeurId());
            //是否更改套餐
            if (apply != null && (!apply.getHirePackageId().equals(packageId))) {
                apply.setStatus(0);
                apply.setId(null);
                chauffeurApplyDao.insert(apply);
            }

            //保存车辆套餐
            chauffeurApplyService.save(chauffeurApply);
            //保存套餐月份租金
            applyMonthService.saveApplyMonths(chauffeurApply, packageId, chauffeurDetail);
        }
        //2.删除工作经历
        chauffeurWorkDao.deleteByChauffeurId(chauffeurDetail.getChauffeurId());
        //3.保存客户的工作信息
        chauffeurWorkService.saveAll(chauffeurDetail);
        //4.删除家庭成员
        chauffeurFamilyDao.deleteByChauffeurId(chauffeurDetail.getChauffeurId());
        //5.保存客户的家庭信息
        chauffeurFamilyService.saveAll(chauffeurDetail);
        //保存当保人
        saveBondsman(chauffeurDetail);

        //2.添加审核过程
        if (!isChangeStatus) {
            chauffeurProcessService.save(chauffeurDetail, preStatus, remarks, "");
        }
        notifyService.notify(chauffeurDetail);

        if(preStatus.equals(ChauffeurStatusV2.BACK_FOR_ADJUST.getValue())) {
            sysUseErrorAggrInfoService.setChauffeurDetail(chauffeurDetail, pre_chauffeurDetail);
        }
    }


    /**
     * @param @param chauffeurDetail
     * @return void
     * @Title: attaUploadForm
     * @Description: 客户附件上传
     */
    @Transactional(readOnly = false)
    public void attaUploadForm(ChauffeurDetail chauffeurDetail) {
        List<Attachment> attachments = chauffeurDetail.getAttachments();
        for (Attachment attachment : attachments) {
            if (attachment.getSize() == null) {
                continue;
            }
            attachment.setRemarks("");
            attachment.setBusinessId(chauffeurDetail.getChauffeurId());
            attachment.setBusinessType("chauffeur");
            attachmentService.save(attachment);
        }
    }

    /**
     * 合同终止
     * @param @param chauffeurDetail
     * @param @param remarks
     * @return void
     * @Title: termination
     * @Description: 
     */
    @Transactional(readOnly = false)
    public void contractTermination(ChauffeurDetail chauffeurDetail, String remarks) {
        //1.修改状态,和终止时间
        Integer status = chauffeurDetail.getStatus();
        User user = UserUtils.getUser();
        Date date = new Date();
        String dateSuffix = "_" + DateUtils.formatDate(date, "yyyyMMdd");

        chauffeurDetail.setStatus(ChauffeurStatusV2.CONTRACT_TERMINATION.getValue());
        chauffeurDetail.setUpdateBy(user);
        chauffeurDetail.setUpdateDate(date);
        chauffeurDetail.setTerminateDate(date);
        chauffeurDetail.setTerminateReason(remarks);
        chauffeurDetail.setMobilePhone(chauffeurDetail.getMobilePhone() + dateSuffix);
        chauffeurDetail.setIdcardNo(chauffeurDetail.getIdcardNo() + dateSuffix);

        Chau
0 回复
添加回复
请先登陆
回到顶部