package com.prolog.rdc.tms.service.fleetManagement.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.prolog.common.util.ToolKits;
import com.prolog.framework.core.exception.ParameterException;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.core.restriction.Order;
import com.prolog.framework.core.restriction.Restriction;
import com.prolog.framework.core.restriction.Restrictions;
import com.prolog.framework.dao.util.PageUtils;
import com.prolog.product.core.framework.entity.UserEntity;
import com.prolog.product.core.framework.util.PlgFxUsrUtils;
import com.prolog.rdc.tms.constant.BussinessConstant;
import com.prolog.rdc.tms.dao.mapper.TVmAccidentregMapper;
import com.prolog.rdc.tms.dao.mapper.TVmFuelRecordMapper;
import com.prolog.rdc.tms.dao.mapper.TVmIllegalRecordMapper;
import com.prolog.rdc.tms.dao.mapper.TVmInsuranceMapper;
import com.prolog.rdc.tms.dao.mapper.TmsRepairRecordDMapper;
import com.prolog.rdc.tms.dao.mapper.TmsRepairRecordHMapper;
import com.prolog.rdc.tms.model.dto.fleetManagement.TVmAccidentregDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.TVmFuelRecordDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.TVmIllegalRecordDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.TVmInsuranceDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.TmsRepairRecordDDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.TmsRepairRecordHDTO;
import com.prolog.rdc.tms.model.entity.line.TVmAccidentregModel;
import com.prolog.rdc.tms.model.entity.line.TVmFuelRecordModel;
import com.prolog.rdc.tms.model.entity.line.TVmIllegalRecordModel;
import com.prolog.rdc.tms.model.entity.line.TVmInsuranceModel;
import com.prolog.rdc.tms.model.entity.line.TmsRepairRecordDModel;
import com.prolog.rdc.tms.model.entity.line.TmsRepairRecordHModel;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmAccidentregAuditQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmAccidentregQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmAccidentregRegisterQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmAccidentregVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmFuelRecordAuditQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmFuelRecordQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmFuelRecordRegisterQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmFuelRecordVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmIllegalRecordAuditQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmIllegalRecordQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmIllegalRecordRegisterQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmIllegalRecordVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmInsuranceAuditQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmInsuranceQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmInsuranceRegisterQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TVmInsuranceVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TmsRepairRecordDVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TmsRepairRecordHAuditQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TmsRepairRecordHQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TmsRepairRecordHRegisterQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TmsRepairRecordHVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.TmsRepairRecordSaveVO;
import com.prolog.rdc.tms.service.fleetManagement.VehicleManageService;

/**
 * 车辆管理 IMPL
 * <p>
 * Copyright: Copyright (C) 2020 prolog-int, Inc. All rights reserved.
 * <p>
 * Company: 湖北普罗格科技股份有限公司
 *
 *
 * @author xiaoyf
 * @since 2020-05-18 17:01
 */
@Service
public class VehicleManageServiceImpl implements VehicleManageService {
	@Autowired
	private TmsRepairRecordHMapper tmsRepairRecordHMapper;

	@Autowired
	private TmsRepairRecordDMapper tmsRepairRecordDMapper;

	@Autowired
	private TVmIllegalRecordMapper tVmIllegalRecordMapper;

	@Autowired
	private TVmAccidentregMapper tVmAccidentregMapper;

	@Autowired
	private TVmInsuranceMapper tVmInsuranceMapper;

	@Autowired
	private TVmFuelRecordMapper tVmFuelRecordMapper;

	/*
	 * 车辆维保查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TmsRepairRecordHDTO> listTmsRepairRecordHData(TmsRepairRecordHQueryVO tmsRepairRecordHQueryVO) {
		ToolKits.isParamNull(tmsRepairRecordHQueryVO, "车辆维保查询请求参数不为空");
		ToolKits.isParamNull(tmsRepairRecordHQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tmsRepairRecordHQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startdate = tmsRepairRecordHQueryVO.getSdate();
		// 结束时间
		Date enddate = tmsRepairRecordHQueryVO.getEdate();

		PageUtils.startPage(tmsRepairRecordHQueryVO.getPageNum(), tmsRepairRecordHQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsRepairRecordHModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tmsRepairRecordHQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tmsRepairRecordHQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tmsRepairRecordHQueryVO.getBillno()) ? null : Restrictions.like("billno", "%" + tmsRepairRecordHQueryVO.getBillno() + "%");
		Restriction r4 = ToolKits.isEmpty(tmsRepairRecordHQueryVO.getVehicleCode()) ? null : Restrictions.like("vehicleCode", "%" + tmsRepairRecordHQueryVO.getVehicleCode() + "%");
		Restriction r5 = ToolKits.isEmpty(tmsRepairRecordHQueryVO.getGsCode()) ? null : Restrictions.like("gsCode", "%" + tmsRepairRecordHQueryVO.getGsCode() + "%");
		Restriction r6 = ToolKits.isEmpty(tmsRepairRecordHQueryVO.getRepairType()) ? null : Restrictions.eq("repairType", tmsRepairRecordHQueryVO.getRepairType());
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startdate) && ToolKits.isEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", startdate, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", new GregorianCalendar(1700, 1, 1).getTime(), enddate);
		} else if (ToolKits.isNotEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", startdate, enddate);
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7));
		criteria.setOrder(Order.newInstance().desc(new String[] { "repairTime" }));
		// 执行查询
		List<TmsRepairRecordHModel> tmsRepairRecordHModels = tmsRepairRecordHMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TmsRepairRecordHDTO> tmsRepairRecordHDTOs = new ArrayList<TmsRepairRecordHDTO>();
		// 循环处理
		for (TmsRepairRecordHModel tmsRepairRecordHModel : tmsRepairRecordHModels) {
			// 响应对象
			TmsRepairRecordHDTO tmsRepairRecordHDTO = new TmsRepairRecordHDTO();
			BeanUtils.copyProperties(tmsRepairRecordHModel, tmsRepairRecordHDTO);

			// 添加响应对象
			tmsRepairRecordHDTOs.add(tmsRepairRecordHDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TmsRepairRecordHDTO> page = PageUtils.getPage(tmsRepairRecordHDTOs);
		if (tmsRepairRecordHModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsRepairRecordHModel> p0 = (com.github.pagehelper.Page<TmsRepairRecordHModel>) tmsRepairRecordHModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆维保审核查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TmsRepairRecordHDTO> listTmsRepairRecordHAuditData(TmsRepairRecordHAuditQueryVO tmsRepairRecordHAuditQueryVO) {
		ToolKits.isParamNull(tmsRepairRecordHAuditQueryVO, "车辆维保审核查询请求参数不为空");
		ToolKits.isParamNull(tmsRepairRecordHAuditQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tmsRepairRecordHAuditQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startdate = tmsRepairRecordHAuditQueryVO.getSdate();
		// 结束时间
		Date enddate = tmsRepairRecordHAuditQueryVO.getEdate();

		PageUtils.startPage(tmsRepairRecordHAuditQueryVO.getPageNum(), tmsRepairRecordHAuditQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsRepairRecordHModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tmsRepairRecordHAuditQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tmsRepairRecordHAuditQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tmsRepairRecordHAuditQueryVO.getBillno()) ? null : Restrictions.like("billno", "%" + tmsRepairRecordHAuditQueryVO.getBillno() + "%");
		Restriction r4 = ToolKits.isEmpty(tmsRepairRecordHAuditQueryVO.getVehicleCode()) ? null : Restrictions.like("vehicleCode", "%" + tmsRepairRecordHAuditQueryVO.getVehicleCode() + "%");
		Restriction r5 = ToolKits.isEmpty(tmsRepairRecordHAuditQueryVO.getGsCode()) ? null : Restrictions.like("gsCode", "%" + tmsRepairRecordHAuditQueryVO.getGsCode() + "%");
		Restriction r6 = ToolKits.isEmpty(tmsRepairRecordHAuditQueryVO.getRepairType()) ? null : Restrictions.eq("repairType", tmsRepairRecordHAuditQueryVO.getRepairType());
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startdate) && ToolKits.isEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", startdate, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", new GregorianCalendar(1700, 1, 1).getTime(), enddate);
		} else if (ToolKits.isNotEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", startdate, enddate);
		}
		Restriction r8 = Restrictions.eq("status", BussinessConstant.TMS_REPAIR_RECORD_COMMIT);
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "repairTime" }));
		// 执行查询
		List<TmsRepairRecordHModel> tmsRepairRecordHModels = tmsRepairRecordHMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TmsRepairRecordHDTO> tmsRepairRecordHDTOs = new ArrayList<TmsRepairRecordHDTO>();
		// 循环处理
		for (TmsRepairRecordHModel tmsRepairRecordHModel : tmsRepairRecordHModels) {
			// 响应对象
			TmsRepairRecordHDTO tmsRepairRecordHDTO = new TmsRepairRecordHDTO();
			BeanUtils.copyProperties(tmsRepairRecordHModel, tmsRepairRecordHDTO);

			// 添加响应对象
			tmsRepairRecordHDTOs.add(tmsRepairRecordHDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TmsRepairRecordHDTO> page = PageUtils.getPage(tmsRepairRecordHDTOs);
		if (tmsRepairRecordHModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsRepairRecordHModel> p0 = (com.github.pagehelper.Page<TmsRepairRecordHModel>) tmsRepairRecordHModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆维保登记查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TmsRepairRecordHDTO> listTmsRepairRecordHRegisterData(TmsRepairRecordHRegisterQueryVO tmsRepairRecordHRegisterQueryVO) {
		ToolKits.isParamNull(tmsRepairRecordHRegisterQueryVO, "车辆维保登记查询请求参数不为空");
		ToolKits.isParamNull(tmsRepairRecordHRegisterQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tmsRepairRecordHRegisterQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startdate = tmsRepairRecordHRegisterQueryVO.getSdate();
		// 结束时间
		Date enddate = tmsRepairRecordHRegisterQueryVO.getEdate();

		PageUtils.startPage(tmsRepairRecordHRegisterQueryVO.getPageNum(), tmsRepairRecordHRegisterQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsRepairRecordHModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tmsRepairRecordHRegisterQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tmsRepairRecordHRegisterQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tmsRepairRecordHRegisterQueryVO.getBillno()) ? null : Restrictions.like("billno", "%" + tmsRepairRecordHRegisterQueryVO.getBillno() + "%");
		Restriction r4 = ToolKits.isEmpty(tmsRepairRecordHRegisterQueryVO.getVehicleCode()) ? null : Restrictions.like("vehicleCode", "%" + tmsRepairRecordHRegisterQueryVO.getVehicleCode() + "%");
		Restriction r5 = ToolKits.isEmpty(tmsRepairRecordHRegisterQueryVO.getGsCode()) ? null : Restrictions.like("gsCode", "%" + tmsRepairRecordHRegisterQueryVO.getGsCode() + "%");
		Restriction r6 = ToolKits.isEmpty(tmsRepairRecordHRegisterQueryVO.getRepairType()) ? null : Restrictions.eq("repairType", tmsRepairRecordHRegisterQueryVO.getRepairType());
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startdate) && ToolKits.isEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", startdate, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", new GregorianCalendar(1700, 1, 1).getTime(), enddate);
		} else if (ToolKits.isNotEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("repairTime", startdate, enddate);
		}
		Restriction r8 = Restrictions.in("status", new String[] { BussinessConstant.TMS_REPAIR_RECORD_REJECT, BussinessConstant.TMS_REPAIR_RECORD_COMMIT });
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "repairTime" }));
		// 执行查询
		List<TmsRepairRecordHModel> tmsRepairRecordHModels = tmsRepairRecordHMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TmsRepairRecordHDTO> tmsRepairRecordHDTOs = new ArrayList<TmsRepairRecordHDTO>();
		// 循环处理
		for (TmsRepairRecordHModel tmsRepairRecordHModel : tmsRepairRecordHModels) {
			// 响应对象
			TmsRepairRecordHDTO tmsRepairRecordHDTO = new TmsRepairRecordHDTO();
			BeanUtils.copyProperties(tmsRepairRecordHModel, tmsRepairRecordHDTO);

			// 添加响应对象
			tmsRepairRecordHDTOs.add(tmsRepairRecordHDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TmsRepairRecordHDTO> page = PageUtils.getPage(tmsRepairRecordHDTOs);
		if (tmsRepairRecordHModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsRepairRecordHModel> p0 = (com.github.pagehelper.Page<TmsRepairRecordHModel>) tmsRepairRecordHModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	// 车辆维保明细信息查询
	@Override
	public List<TmsRepairRecordDDTO> queryTmsRepairRecordD(TmsRepairRecordDVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		if (ToolKits.isEmpty(vo.getBillno())) {
			throw new ParameterException("维修保养单号不能为空！");
		}
		Criteria criteria = Criteria.forClass(TmsRepairRecordDModel.class);
		Restriction r1 = ToolKits.isEmpty(vo.getBranchId()) ? null : Restrictions.eq("branchid", vo.getBranchId());
		Restriction r2 = ToolKits.isEmpty(vo.getBillno()) ? null : Restrictions.eq("billno", vo.getBillno());
		criteria.setRestriction(Restrictions.and(r1, r2));
		List<TmsRepairRecordDModel> list = tmsRepairRecordDMapper.findByCriteria(criteria);
		List<TmsRepairRecordDDTO> dtolist = new ArrayList<TmsRepairRecordDDTO>();
		for (TmsRepairRecordDModel model : list) {
			TmsRepairRecordDDTO dto = new TmsRepairRecordDDTO();
			BeanUtils.copyProperties(model, dto);
			dtolist.add(dto);
		}
		return dtolist;
	}

	// 车辆维保信息保存
	@Override
	public void tmsRepairRecordSave(TmsRepairRecordSaveVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		TmsRepairRecordHVO hvo = vo.getHvo();
		if (ToolKits.isEmpty(hvo)) {
			throw new ParameterException("汇总数据不能为空！");
		}
		if (CollectionUtils.isEmpty(vo.getList())) {
			throw new ParameterException("明细数据不能为空！");
		}
		if (ToolKits.isEmpty(hvo.getBranchId())) {
			throw new ParameterException("机构不能为空！");
		}
		if (ToolKits.isEmpty(hvo.getBranchname())) {
			throw new ParameterException("机构名称不能为空！");
		}
		if (ToolKits.isEmpty(hvo.getBillno())) {
			throw new ParameterException("维保单号不能为空！");
		}
		TmsRepairRecordHModel model = tmsRepairRecordHMapper.findById(hvo.getBillno(), TmsRepairRecordHModel.class);
		if (ToolKits.isNotEmpty(model)) {
			throw new ParameterException("维保单号已存在！");
		}
		TmsRepairRecordHModel hmodel = new TmsRepairRecordHModel();
		BeanUtils.copyProperties(hvo, hmodel);
		hmodel.setCreateperson(user.getNickname());
		hmodel.setCreatetime(new Date());
		hmodel.setStatus("10");// 状态 待字典数据定义 暂为10
		// 保存维保汇总
		tmsRepairRecordHMapper.save(hmodel);

		List<TmsRepairRecordDModel> dmodellist = new ArrayList<TmsRepairRecordDModel>();

		for (TmsRepairRecordDVO dvo : vo.getList()) {
			TmsRepairRecordDModel dmodel = new TmsRepairRecordDModel();
			BeanUtils.copyProperties(dvo, dmodel);
			dmodel.setLineid(ToolKits.getUUID());
			dmodel.setBranchId(hvo.getBranchId());
			dmodel.setBranchname(hvo.getBranchname());
			dmodel.setBillno(hvo.getBillno());
			dmodel.setCreateperson(user.getNickname());
			dmodel.setCreatetime(new Date());
			dmodellist.add(dmodel);
		}
		// 保存维保明细
		tmsRepairRecordDMapper.saveBatch(dmodellist);
	}

	// 车辆维保信息修改
	@Override
	public void tmsRepairRecordUpdate(TmsRepairRecordSaveVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		TmsRepairRecordHVO hvo = vo.getHvo();
		if (ToolKits.isEmpty(hvo)) {
			throw new ParameterException("汇总数据不能为空！");
		}
		TmsRepairRecordHModel hmodel = tmsRepairRecordHMapper.findById(hvo.getBillno(), TmsRepairRecordHModel.class);
		BeanUtils.copyProperties(hvo, hmodel);
		hmodel.setStatus(BussinessConstant.TMS_REPAIR_RECORD_COMMIT);
		hmodel.setUpdateperson(user.getNickname());
		hmodel.setUpdatetime(new Date());
		tmsRepairRecordHMapper.update(hmodel);

		for (TmsRepairRecordDVO dvo : vo.getList()) {
			if (ToolKits.isEmpty(dvo.getLineid())) {// 新增明细
				TmsRepairRecordDModel dmodel = new TmsRepairRecordDModel();
				BeanUtils.copyProperties(dvo, dmodel);
				dmodel.setLineid(ToolKits.getUUID());
				dmodel.setBranchId(hvo.getBranchId());
				dmodel.setBranchname(hvo.getBranchname());
				dmodel.setBillno(hmodel.getBillno());
				dmodel.setCreateperson(user.getNickname());
				dmodel.setCreatetime(new Date());
				tmsRepairRecordDMapper.save(dmodel);
			} else {// 更新明细
				TmsRepairRecordDModel dmodel = tmsRepairRecordDMapper.findById(dvo.getLineid(), TmsRepairRecordDModel.class);
				BeanUtils.copyProperties(dvo, dmodel);
				dmodel.setLineid(ToolKits.getUUID());
				dmodel.setUpdateperson(user.getNickname());
				dmodel.setUpdatetime(new Date());
				tmsRepairRecordDMapper.update(dmodel);
			}
		}

	}

	// 车辆维保信息汇总删除
	@Override
	public void tmsRepairRecordDelete(List<TmsRepairRecordHVO> vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		for (TmsRepairRecordHVO tmsRepairRecordHVo : vo) {
			TmsRepairRecordHModel hmodel = tmsRepairRecordHMapper.findById(tmsRepairRecordHVo.getBillno(), TmsRepairRecordHModel.class);
			tmsRepairRecordHMapper.deleteById(hmodel.getBillno(), TmsRepairRecordHModel.class);
			// 删除明细
			Criteria criteria = Criteria.forClass(TmsRepairRecordDModel.class);
			Restriction r1 = ToolKits.isEmpty(hmodel.getBillno()) ? null : Restrictions.eq("billno", hmodel.getBillno());
			criteria.setRestriction(r1);
			tmsRepairRecordDMapper.deleteByCriteria(criteria);
		}
	}

	// 车辆维保明细删除
	@Override
	public void tmsRepairRecordDDelete(List<TmsRepairRecordDVO> vos) {
		String[] ids = new String[vos.size()];
		int i = 0;
		for (TmsRepairRecordDVO dvo : vos) {
			ids[i] = dvo.getLineid();
			i++;
		}
		if (ids.length > 0) {
			tmsRepairRecordDMapper.deleteByIds(ids, TmsRepairRecordDModel.class);
		}
	}

	// 车辆维保审核
	@Override
	public void tmsRepairRecordAudit(TmsRepairRecordHVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		Date date = new Date();
		TmsRepairRecordHModel hmodel = tmsRepairRecordHMapper.findById(vo.getBillno(), TmsRepairRecordHModel.class);
		hmodel.setStatus(BussinessConstant.TMS_REPAIR_RECORD_AUDIT);
		hmodel.setAudittime(date);
		hmodel.setAuditperson(user.getNickname());
		hmodel.setUpdateperson(user.getNickname());
		hmodel.setUpdatetime(date);
		hmodel.setAuditdescrible(vo.getAuditdescrible());
		tmsRepairRecordHMapper.update(hmodel);
	}

	// 车辆维保驳回
	@Override
	public void tmsRepairRecordReject(TmsRepairRecordHVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		if (ToolKits.isEmpty(vo.getAuditdescrible())) {
			throw new ParameterException("审核意见不能为空！");
		}
		Date date = new Date();
		TmsRepairRecordHModel hmodel = tmsRepairRecordHMapper.findById(vo.getBillno(), TmsRepairRecordHModel.class);
		hmodel.setStatus(BussinessConstant.TMS_REPAIR_RECORD_REJECT);
		hmodel.setAudittime(date);
		hmodel.setAuditperson(user.getNickname());
		hmodel.setUpdateperson(user.getNickname());
		hmodel.setUpdatetime(date);
		hmodel.setAuditdescrible(vo.getAuditdescrible());// 审核意见
		tmsRepairRecordHMapper.update(hmodel);
	}

	// 车辆违章登记保存
	@Override
	public void tVmIllegalRecordSave(TVmIllegalRecordVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		if (ToolKits.isEmpty(vo.getBranchId())) {
			throw new ParameterException("机构不能为空！");
		}
		if (ToolKits.isEmpty(vo.getBranchname())) {
			throw new ParameterException("机构名称不能为空！");
		}
		Criteria criteria = Criteria.forClass(TVmIllegalRecordModel.class);
		Restriction r1 = ToolKits.isEmpty(vo.getIllegalNo()) ? null : Restrictions.eq("illegalNo", vo.getIllegalNo());
		criteria.setRestriction(Restrictions.and(r1));
		List<TVmIllegalRecordModel> list = tVmIllegalRecordMapper.findByCriteria(criteria);
		if (!CollectionUtils.isEmpty(list)) {
			throw new RuntimeException("违章单号已存在！");
		}
		// 发生illegalTime,发现discoverTime,处理disposeTime
		if (vo.getDiscoverTime().before(vo.getIllegalTime())) {
			throw new ParameterException("违章发现时间需在违章发生时间之后！");
		}
		if (vo.getDisposeTime().before(vo.getDiscoverTime())) {
			throw new ParameterException("违章处理时间需在违章发现时间之后！");
		}
		TVmIllegalRecordModel tVmIllegalRecord = new TVmIllegalRecordModel();
		BeanUtils.copyProperties(vo, tVmIllegalRecord);
		tVmIllegalRecord.setCreateperson(user.getNickname());
		tVmIllegalRecord.setCreatetime(new Date());
		tVmIllegalRecord.setStatus(BussinessConstant.TMS_VEHICLE_ILLEGAL_COMMIT);
		tVmIllegalRecordMapper.save(tVmIllegalRecord);
	}

	// 车辆违章登记修改
	@Override
	public void tVmIllegalRecordUpdate(TVmIllegalRecordVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		TVmIllegalRecordModel tVmIllegalRecordModel = tVmIllegalRecordMapper.findById(vo.getIllegalNo(), TVmIllegalRecordModel.class);
		BeanUtils.copyProperties(vo, tVmIllegalRecordModel);
		tVmIllegalRecordModel.setUpdateperson(user.getNickname());
		tVmIllegalRecordModel.setUpdatetime(new Date());
		tVmIllegalRecordModel.setStatus(BussinessConstant.TMS_VEHICLE_ILLEGAL_COMMIT);
		tVmIllegalRecordMapper.update(tVmIllegalRecordModel);
	}

	// 车辆违章登记删除
	@Override
	public void tVmIllegalRecordDelete(List<TVmIllegalRecordVO> vos) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		String[] ids = new String[vos.size()];
		int i = 0;
		for (TVmIllegalRecordVO vo : vos) {
			ids[i] = vo.getIllegalNo();
			i++;
		}
		if (ids.length > 0) {
			tVmIllegalRecordMapper.deleteByIds(ids, TVmIllegalRecordModel.class);
		}
	}

	/*
	 * 车辆违章查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmIllegalRecordDTO> listTVmIllegalRecordData(TVmIllegalRecordQueryVO tVmIllegalRecordQueryVO) {
		ToolKits.isParamNull(tVmIllegalRecordQueryVO, "车辆违章查询请求参数不为空");
		ToolKits.isParamNull(tVmIllegalRecordQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmIllegalRecordQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startTime = tVmIllegalRecordQueryVO.getSdate();
		// 结束时间
		Date endTime = tVmIllegalRecordQueryVO.getEdate();

		PageUtils.startPage(tVmIllegalRecordQueryVO.getPageNum(), tVmIllegalRecordQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmIllegalRecordModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmIllegalRecordQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmIllegalRecordQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmIllegalRecordQueryVO.getIllegalNo()) ? null : Restrictions.like("illegalNo", "%" + tVmIllegalRecordQueryVO.getIllegalNo() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmIllegalRecordQueryVO.getIllegalType()) ? null : Restrictions.eq("illegalType", tVmIllegalRecordQueryVO.getIllegalType());
		Restriction r5 = ToolKits.isEmpty(tVmIllegalRecordQueryVO.getIllegalPerson()) ? null : Restrictions.like("illegalPerson", "%" + tVmIllegalRecordQueryVO.getIllegalPerson() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmIllegalRecordQueryVO.getVehicleCode()) ? null : Restrictions.like("vehicleCode", "%" + tVmIllegalRecordQueryVO.getVehicleCode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", startTime, endTime);
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7));
		criteria.setOrder(Order.newInstance().desc(new String[] { "illegalTime" }));
		// 执行查询
		List<TVmIllegalRecordModel> tVmIllegalRecordModels = tVmIllegalRecordMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmIllegalRecordDTO> tVmIllegalRecordDTOs = new ArrayList<TVmIllegalRecordDTO>();
		// 循环处理
		for (TVmIllegalRecordModel tVmIllegalRecordModel : tVmIllegalRecordModels) {
			// 响应对象
			TVmIllegalRecordDTO tVmIllegalRecordDTO = new TVmIllegalRecordDTO();
			BeanUtils.copyProperties(tVmIllegalRecordModel, tVmIllegalRecordDTO);

			// 添加响应对象
			tVmIllegalRecordDTOs.add(tVmIllegalRecordDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmIllegalRecordDTO> page = PageUtils.getPage(tVmIllegalRecordDTOs);
		if (tVmIllegalRecordModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmIllegalRecordModel> p0 = (com.github.pagehelper.Page<TVmIllegalRecordModel>) tVmIllegalRecordModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆违章审核查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmIllegalRecordDTO> listTVmIllegalRecordAuditData(TVmIllegalRecordAuditQueryVO tVmIllegalRecordAuditQueryVO) {
		ToolKits.isParamNull(tVmIllegalRecordAuditQueryVO, "车辆违章审核查询请求参数不为空");
		ToolKits.isParamNull(tVmIllegalRecordAuditQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmIllegalRecordAuditQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(user.getWarehouses().toArray(), "当前人员没有所属配送中心权限");

		// 开始时间
		Date startTime = tVmIllegalRecordAuditQueryVO.getSdate();
		// 结束时间
		Date endTime = tVmIllegalRecordAuditQueryVO.getEdate();

		PageUtils.startPage(tVmIllegalRecordAuditQueryVO.getPageNum(), tVmIllegalRecordAuditQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmIllegalRecordModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmIllegalRecordAuditQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmIllegalRecordAuditQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmIllegalRecordAuditQueryVO.getIllegalNo()) ? null : Restrictions.like("illegalNo", "%" + tVmIllegalRecordAuditQueryVO.getIllegalNo() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmIllegalRecordAuditQueryVO.getIllegalType()) ? null : Restrictions.eq("illegalType", tVmIllegalRecordAuditQueryVO.getIllegalType());
		Restriction r5 = ToolKits.isEmpty(tVmIllegalRecordAuditQueryVO.getIllegalPerson()) ? null : Restrictions.like("illegalPerson", "%" + tVmIllegalRecordAuditQueryVO.getIllegalPerson() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmIllegalRecordAuditQueryVO.getVehicleCode()) ? null : Restrictions.like("vehicleCode", "%" + tVmIllegalRecordAuditQueryVO.getVehicleCode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", startTime, endTime);
		}
		Restriction r8 = Restrictions.eq("status", BussinessConstant.TMS_VEHICLE_ILLEGAL_COMMIT);
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "illegalTime" }));
		// 执行查询
		List<TVmIllegalRecordModel> tVmIllegalRecordModels = tVmIllegalRecordMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmIllegalRecordDTO> tVmIllegalRecordDTOs = new ArrayList<TVmIllegalRecordDTO>();
		// 循环处理
		for (TVmIllegalRecordModel tVmIllegalRecordModel : tVmIllegalRecordModels) {
			// 响应对象
			TVmIllegalRecordDTO tVmIllegalRecordDTO = new TVmIllegalRecordDTO();
			BeanUtils.copyProperties(tVmIllegalRecordModel, tVmIllegalRecordDTO);

			// 添加响应对象
			tVmIllegalRecordDTOs.add(tVmIllegalRecordDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmIllegalRecordDTO> page = PageUtils.getPage(tVmIllegalRecordDTOs);
		if (tVmIllegalRecordModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmIllegalRecordModel> p0 = (com.github.pagehelper.Page<TVmIllegalRecordModel>) tVmIllegalRecordModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆违章登记查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmIllegalRecordDTO> listTVmIllegalRecordRegisterData(TVmIllegalRecordRegisterQueryVO tVmIllegalRecordRegisterQueryVO) {
		ToolKits.isParamNull(tVmIllegalRecordRegisterQueryVO, "车辆违章登记查询请求参数不为空");
		ToolKits.isParamNull(tVmIllegalRecordRegisterQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmIllegalRecordRegisterQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(user.getWarehouses().toArray(), "当前人员没有所属配送中心权限");

		// 开始时间
		Date startTime = tVmIllegalRecordRegisterQueryVO.getSdate();
		// 结束时间
		Date endTime = tVmIllegalRecordRegisterQueryVO.getEdate();

		PageUtils.startPage(tVmIllegalRecordRegisterQueryVO.getPageNum(), tVmIllegalRecordRegisterQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmIllegalRecordModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmIllegalRecordRegisterQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmIllegalRecordRegisterQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmIllegalRecordRegisterQueryVO.getIllegalNo()) ? null : Restrictions.like("illegalNo", "%" + tVmIllegalRecordRegisterQueryVO.getIllegalNo() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmIllegalRecordRegisterQueryVO.getIllegalType()) ? null : Restrictions.eq("illegalType", tVmIllegalRecordRegisterQueryVO.getIllegalType());
		Restriction r5 = ToolKits.isEmpty(tVmIllegalRecordRegisterQueryVO.getIllegalPerson()) ? null : Restrictions.like("illegalPerson", "%" + tVmIllegalRecordRegisterQueryVO.getIllegalPerson() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmIllegalRecordRegisterQueryVO.getVehicleCode()) ? null : Restrictions.like("vehicleCode", "%" + tVmIllegalRecordRegisterQueryVO.getVehicleCode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("illegalTime", startTime, endTime);
		}
		Restriction r8 = Restrictions.in("status", new String[] { BussinessConstant.TMS_VEHICLE_ILLEGAL_REJECT, BussinessConstant.TMS_VEHICLE_ILLEGAL_COMMIT });
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "illegalTime" }));
		// 执行查询
		List<TVmIllegalRecordModel> tVmIllegalRecordModels = tVmIllegalRecordMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmIllegalRecordDTO> tVmIllegalRecordDTOs = new ArrayList<TVmIllegalRecordDTO>();
		// 循环处理
		for (TVmIllegalRecordModel tVmIllegalRecordModel : tVmIllegalRecordModels) {
			// 响应对象
			TVmIllegalRecordDTO tVmIllegalRecordDTO = new TVmIllegalRecordDTO();
			BeanUtils.copyProperties(tVmIllegalRecordModel, tVmIllegalRecordDTO);

			// 添加响应对象
			tVmIllegalRecordDTOs.add(tVmIllegalRecordDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmIllegalRecordDTO> page = PageUtils.getPage(tVmIllegalRecordDTOs);
		if (tVmIllegalRecordModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmIllegalRecordModel> p0 = (com.github.pagehelper.Page<TVmIllegalRecordModel>) tVmIllegalRecordModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	// 车辆违章审核
	@Override
	public void tVmIllegalRecordAudit(TVmIllegalRecordVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		Date date = new Date();
		TVmIllegalRecordModel model = tVmIllegalRecordMapper.findById(vo.getIllegalNo(), TVmIllegalRecordModel.class);
		model.setStatus(BussinessConstant.TMS_VEHICLE_ILLEGAL_AUDIT);
		model.setAudittime(date);
		model.setAuditperson(user.getNickname());
		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(date);
		if (ToolKits.isNotEmpty(vo.getExtend01())) {// 审核意见
			model.setExtend01(vo.getExtend01());
		}
		tVmIllegalRecordMapper.update(model);
	}

	// 车辆违章驳回
	@Override
	public void tVmIllegalRecordReject(TVmIllegalRecordVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		if (ToolKits.isNotEmpty(vo.getExtend01())) {// 审核意见
			throw new ParameterException("审核意见不能为空！");
		}
		TVmIllegalRecordModel model = tVmIllegalRecordMapper.findById(vo.getIllegalNo(), TVmIllegalRecordModel.class);
		model.setStatus(BussinessConstant.TMS_VEHICLE_ILLEGAL_REJECT);
		model.setAudittime(new Date());
		model.setAuditperson(user.getNickname());
		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(new Date());
		model.setExtend01(vo.getExtend01());
		tVmIllegalRecordMapper.update(model);
	}

	/*
	 * 车辆事故查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmAccidentregDTO> listTVmAccidentregData(TVmAccidentregQueryVO tVmAccidentregQueryVO) {
		ToolKits.isParamNull(tVmAccidentregQueryVO, "车辆事故查询请求参数不为空");
		ToolKits.isParamNull(tVmAccidentregQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmAccidentregQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(user.getWarehouses().toArray(), "当前人员没有所属配送中心权限");

		// 开始时间
		Date startTime = tVmAccidentregQueryVO.getStartdate();
		// 结束时间
		Date endTime = tVmAccidentregQueryVO.getEnddate();

		PageUtils.startPage(tVmAccidentregQueryVO.getPageNum(), tVmAccidentregQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmAccidentregModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmAccidentregQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmAccidentregQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmAccidentregQueryVO.getAccidentNum()) ? null : Restrictions.like("accidentNum", "%" + tVmAccidentregQueryVO.getAccidentNum() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmAccidentregQueryVO.getAccidaddress()) ? null : Restrictions.like("accidaddress", "%" + tVmAccidentregQueryVO.getAccidaddress() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmAccidentregQueryVO.getReporter()) ? null : Restrictions.like("reporter", "%" + tVmAccidentregQueryVO.getReporter() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmAccidentregQueryVO.getVehiclecode()) ? null : Restrictions.like("vehiclecode", "%" + tVmAccidentregQueryVO.getVehiclecode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", startTime, endTime);
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7));
		criteria.setOrder(Order.newInstance().desc(new String[] { "acciddate" }));
		// 执行查询
		List<TVmAccidentregModel> tVmAccidentregModels = tVmAccidentregMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmAccidentregDTO> tVmAccidentregDTOs = new ArrayList<TVmAccidentregDTO>();
		// 循环处理
		for (TVmAccidentregModel tVmAccidentregModel : tVmAccidentregModels) {
			// 响应对象
			TVmAccidentregDTO tVmAccidentregDTO = new TVmAccidentregDTO();
			BeanUtils.copyProperties(tVmAccidentregModel, tVmAccidentregDTO);

			// 添加响应对象
			tVmAccidentregDTOs.add(tVmAccidentregDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmAccidentregDTO> page = PageUtils.getPage(tVmAccidentregDTOs);
		if (tVmAccidentregModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmAccidentregModel> p0 = (com.github.pagehelper.Page<TVmAccidentregModel>) tVmAccidentregModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆事故审核查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmAccidentregDTO> listTVmAccidentregAuditData(TVmAccidentregAuditQueryVO tVmAccidentregAuditQueryVO) {
		ToolKits.isParamNull(tVmAccidentregAuditQueryVO, "车辆事故审核查询请求参数不为空");
		ToolKits.isParamNull(tVmAccidentregAuditQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmAccidentregAuditQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startTime = tVmAccidentregAuditQueryVO.getStartdate();
		// 结束时间
		Date endTime = tVmAccidentregAuditQueryVO.getEnddate();

		PageUtils.startPage(tVmAccidentregAuditQueryVO.getPageNum(), tVmAccidentregAuditQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmAccidentregModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmAccidentregAuditQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmAccidentregAuditQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmAccidentregAuditQueryVO.getAccidentNum()) ? null : Restrictions.like("accidentNum", "%" + tVmAccidentregAuditQueryVO.getAccidentNum() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmAccidentregAuditQueryVO.getAccidaddress()) ? null : Restrictions.like("accidaddress", "%" + tVmAccidentregAuditQueryVO.getAccidaddress() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmAccidentregAuditQueryVO.getReporter()) ? null : Restrictions.like("reporter", "%" + tVmAccidentregAuditQueryVO.getReporter() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmAccidentregAuditQueryVO.getVehiclecode()) ? null : Restrictions.like("vehiclecode", "%" + tVmAccidentregAuditQueryVO.getVehiclecode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", startTime, endTime);
		}
		Restriction r8 = Restrictions.eq("status", BussinessConstant.T_VM_ACCIDENTREG_COMMIT);
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "acciddate" }));
		// 执行查询
		List<TVmAccidentregModel> tVmAccidentregModels = tVmAccidentregMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmAccidentregDTO> tVmAccidentregDTOs = new ArrayList<TVmAccidentregDTO>();
		// 循环处理
		for (TVmAccidentregModel tVmAccidentregModel : tVmAccidentregModels) {
			// 响应对象
			TVmAccidentregDTO tVmAccidentregDTO = new TVmAccidentregDTO();
			BeanUtils.copyProperties(tVmAccidentregModel, tVmAccidentregDTO);

			// 添加响应对象
			tVmAccidentregDTOs.add(tVmAccidentregDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmAccidentregDTO> page = PageUtils.getPage(tVmAccidentregDTOs);
		if (tVmAccidentregModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmAccidentregModel> p0 = (com.github.pagehelper.Page<TVmAccidentregModel>) tVmAccidentregModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆事故登记查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmAccidentregDTO> listTVmAccidentregRegisterData(TVmAccidentregRegisterQueryVO tVmAccidentregRegisterQueryVO) {
		ToolKits.isParamNull(tVmAccidentregRegisterQueryVO, "车辆事故登记查询请求参数不为空");
		ToolKits.isParamNull(tVmAccidentregRegisterQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmAccidentregRegisterQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(user.getWarehouses().toArray(), "当前人员没有所属配送中心权限");

		// 开始时间
		Date startTime = tVmAccidentregRegisterQueryVO.getStartdate();
		// 结束时间
		Date endTime = tVmAccidentregRegisterQueryVO.getEnddate();

		PageUtils.startPage(tVmAccidentregRegisterQueryVO.getPageNum(), tVmAccidentregRegisterQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmAccidentregModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmAccidentregRegisterQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmAccidentregRegisterQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmAccidentregRegisterQueryVO.getAccidentNum()) ? null : Restrictions.like("accidentNum", "%" + tVmAccidentregRegisterQueryVO.getAccidentNum() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmAccidentregRegisterQueryVO.getAccidaddress()) ? null : Restrictions.like("accidaddress", "%" + tVmAccidentregRegisterQueryVO.getAccidaddress() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmAccidentregRegisterQueryVO.getReporter()) ? null : Restrictions.like("reporter", "%" + tVmAccidentregRegisterQueryVO.getReporter() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmAccidentregRegisterQueryVO.getVehiclecode()) ? null : Restrictions.like("vehiclecode", "%" + tVmAccidentregRegisterQueryVO.getVehiclecode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("acciddate", startTime, endTime);
		}
		Restriction r8 = Restrictions.in("status", new String[] { BussinessConstant.T_VM_ACCIDENTREG_REJECT, BussinessConstant.T_VM_ACCIDENTREG_COMMIT });
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "acciddate" }));
		// 执行查询
		List<TVmAccidentregModel> tVmAccidentregModels = tVmAccidentregMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmAccidentregDTO> tVmAccidentregDTOs = new ArrayList<TVmAccidentregDTO>();
		// 循环处理
		for (TVmAccidentregModel tVmAccidentregModel : tVmAccidentregModels) {
			// 响应对象
			TVmAccidentregDTO tVmAccidentregDTO = new TVmAccidentregDTO();
			BeanUtils.copyProperties(tVmAccidentregModel, tVmAccidentregDTO);

			// 添加响应对象
			tVmAccidentregDTOs.add(tVmAccidentregDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmAccidentregDTO> page = PageUtils.getPage(tVmAccidentregDTOs);
		if (tVmAccidentregModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmAccidentregModel> p0 = (com.github.pagehelper.Page<TVmAccidentregModel>) tVmAccidentregModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	// 车辆事故登记
	@Override
	public void tVmAccidentregSave(TVmAccidentregVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		if (ToolKits.isEmpty(vo.getBranchId())) {
			throw new ParameterException("机构不能为空！");
		}
		if (ToolKits.isEmpty(vo.getAccidentNum())) {
			throw new ParameterException("事故编号不能为空！");
		}
		// 校验事故日期
		if (vo.getAcciddate().after(vo.getReportdate())) {
			throw new ParameterException("事故日期需在报案日期之前！");
		}
		Criteria criteria = Criteria.forClass(TVmAccidentregModel.class);
		Restriction r1 = ToolKits.isEmpty(vo.getAccidentNum()) ? null : Restrictions.eq("accidentNum", vo.getAccidentNum());
		criteria.setRestriction(Restrictions.and(r1));
		List<TVmAccidentregModel> list = tVmAccidentregMapper.findByCriteria(criteria);
		if (!CollectionUtils.isEmpty(list)) {
			throw new RuntimeException("事故单号已存在！");
		}

		TVmAccidentregModel model = new TVmAccidentregModel();
		BeanUtils.copyProperties(vo, model);
		model.setCreateperson(user.getNickname());
		model.setCreatetime(new Date());
		model.setStatus(BussinessConstant.T_VM_ACCIDENTREG_COMMIT);
		tVmAccidentregMapper.save(model);
	}

	// 车辆事故修改
	@Override
	public void tVmAccidentregUpdate(TVmAccidentregVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		TVmAccidentregModel tVmIllegalRecordModel = tVmAccidentregMapper.findById(vo.getAccidentNum(), TVmAccidentregModel.class);
		BeanUtils.copyProperties(vo, tVmIllegalRecordModel);
		tVmIllegalRecordModel.setStatus(BussinessConstant.T_VM_ACCIDENTREG_COMMIT);
		tVmIllegalRecordModel.setUpdateperson(user.getNickname());
		tVmIllegalRecordModel.setUpdatetime(new Date());
		tVmAccidentregMapper.update(tVmIllegalRecordModel);
	}

	// 车辆事故删除
	@Override
	public void tVmAccidentregDelete(List<TVmAccidentregVO> vos) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		ToolKits.isParamNull(vos, "参数不能为空！");

		String[] ids = new String[vos.size()];
		int i = 0;
		for (TVmAccidentregVO vo : vos) {
			ids[i] = vo.getAccidentNum();
			i++;
		}
		if (ids.length > 0) {
			tVmAccidentregMapper.deleteByIds(ids, TVmAccidentregModel.class);
		}
	}

	// 车辆事故审核
	@Override
	public void tVmAccidentregAudit(TVmAccidentregVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		TVmAccidentregModel model = tVmAccidentregMapper.findById(vo.getAccidentNum(), TVmAccidentregModel.class);
		model.setStatus(BussinessConstant.T_VM_ACCIDENTREG_AUDIT);
		model.setAudittime(new Date());
		model.setAuditperson(user.getNickname());
		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(new Date());
		model.setAuditdescrible(vo.getAuditdescrible());
		tVmAccidentregMapper.update(model);
	}

	// 车辆事故驳回
	@Override
	public void tVmAccidentregReject(TVmAccidentregVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		TVmAccidentregModel model = tVmAccidentregMapper.findById(vo.getAccidentNum(), TVmAccidentregModel.class);
		model.setStatus(BussinessConstant.T_VM_ACCIDENTREG_REJECT);
		model.setAudittime(new Date());
		model.setAuditperson(user.getNickname());
		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(new Date());
		model.setAuditdescrible(vo.getAuditdescrible());
		tVmAccidentregMapper.update(model);
	}

	/*
	 * 车辆保险查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmInsuranceDTO> listTVmInsuranceData(TVmInsuranceQueryVO tVmInsuranceQueryVO) {
		ToolKits.isParamNull(tVmInsuranceQueryVO, "车辆保险查询请求参数不为空");
		ToolKits.isParamNull(tVmInsuranceQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmInsuranceQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(user.getWarehouses().toArray(), "当前人员没有所属配送中心权限");

		// 开始时间
		Date startTime = tVmInsuranceQueryVO.getStartTime();
		// 结束时间
		Date endTime = tVmInsuranceQueryVO.getEndTime();

		PageUtils.startPage(tVmInsuranceQueryVO.getPageNum(), tVmInsuranceQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmInsuranceModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmInsuranceQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmInsuranceQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmInsuranceQueryVO.getInsurcode()) ? null : Restrictions.like("insurcode", "%" + tVmInsuranceQueryVO.getInsurcode() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmInsuranceQueryVO.getPlatenumber()) ? null : Restrictions.like("platenumber", "%" + tVmInsuranceQueryVO.getPlatenumber() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmInsuranceQueryVO.getReporter()) ? null : Restrictions.like("reporter", "%" + tVmInsuranceQueryVO.getReporter() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmInsuranceQueryVO.getPaidCustomer()) ? null : Restrictions.like("paidCustomer", "%" + tVmInsuranceQueryVO.getPaidCustomer() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("outdager", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("outdager", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("outdager", startTime, endTime);
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7));
		criteria.setOrder(Order.newInstance().desc(new String[] { "outdager" }));
		// 执行查询
		List<TVmInsuranceModel> tVmInsuranceModels = tVmInsuranceMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmInsuranceDTO> tVmInsuranceDTOs = new ArrayList<TVmInsuranceDTO>();
		// 循环处理
		for (TVmInsuranceModel tVmInsuranceModel : tVmInsuranceModels) {
			// 响应对象
			TVmInsuranceDTO tVmInsuranceDTO = new TVmInsuranceDTO();
			BeanUtils.copyProperties(tVmInsuranceModel, tVmInsuranceDTO);

			// 添加响应对象
			tVmInsuranceDTOs.add(tVmInsuranceDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmInsuranceDTO> page = PageUtils.getPage(tVmInsuranceDTOs);
		if (tVmInsuranceModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmInsuranceModel> p0 = (com.github.pagehelper.Page<TVmInsuranceModel>) tVmInsuranceModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆保险审核查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmInsuranceDTO> listTVmInsuranceAuditData(TVmInsuranceAuditQueryVO tVmInsuranceAuditQueryVO) {
		ToolKits.isParamNull(tVmInsuranceAuditQueryVO, "车辆保险审核查询请求参数不为空");
		ToolKits.isParamNull(tVmInsuranceAuditQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmInsuranceAuditQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startTime = tVmInsuranceAuditQueryVO.getStartTime();
		// 结束时间
		Date endTime = tVmInsuranceAuditQueryVO.getEndTime();

		PageUtils.startPage(tVmInsuranceAuditQueryVO.getPageNum(), tVmInsuranceAuditQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmInsuranceModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmInsuranceAuditQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmInsuranceAuditQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmInsuranceAuditQueryVO.getInsurcode()) ? null : Restrictions.like("insurcode", "%" + tVmInsuranceAuditQueryVO.getInsurcode() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmInsuranceAuditQueryVO.getPlatenumber()) ? null : Restrictions.like("platenumber", "%" + tVmInsuranceAuditQueryVO.getPlatenumber() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmInsuranceAuditQueryVO.getReporter()) ? null : Restrictions.like("reporter", "%" + tVmInsuranceAuditQueryVO.getReporter() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmInsuranceAuditQueryVO.getPaidCustomer()) ? null : Restrictions.like("paidCustomer", "%" + tVmInsuranceAuditQueryVO.getPaidCustomer() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("outdager", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("outdager", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("outdager", startTime, endTime);
		}
		Restriction r8 = Restrictions.eq("status", BussinessConstant.T_VM_INSURANCE_COMMIT);
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "outdager" }));
		// 执行查询
		List<TVmInsuranceModel> tVmInsuranceModels = tVmInsuranceMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmInsuranceDTO> tVmInsuranceDTOs = new ArrayList<TVmInsuranceDTO>();
		// 循环处理
		for (TVmInsuranceModel tVmInsuranceModel : tVmInsuranceModels) {
			// 响应对象
			TVmInsuranceDTO tVmInsuranceDTO = new TVmInsuranceDTO();
			BeanUtils.copyProperties(tVmInsuranceModel, tVmInsuranceDTO);

			// 添加响应对象
			tVmInsuranceDTOs.add(tVmInsuranceDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmInsuranceDTO> page = PageUtils.getPage(tVmInsuranceDTOs);
		if (tVmInsuranceModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmInsuranceModel> p0 = (com.github.pagehelper.Page<TVmInsuranceModel>) tVmInsuranceModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆保险登记查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmInsuranceDTO> listTVmInsuranceRegisterData(TVmInsuranceRegisterQueryVO tVmInsuranceRegisterQueryVO) {
		ToolKits.isParamNull(tVmInsuranceRegisterQueryVO, "车辆保险登记查询请求参数不为空");
		ToolKits.isParamNull(tVmInsuranceRegisterQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmInsuranceRegisterQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startTime = tVmInsuranceRegisterQueryVO.getStartTime();
		// 结束时间
		Date endTime = tVmInsuranceRegisterQueryVO.getEndTime();

		PageUtils.startPage(tVmInsuranceRegisterQueryVO.getPageNum(), tVmInsuranceRegisterQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmInsuranceModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmInsuranceRegisterQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmInsuranceRegisterQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmInsuranceRegisterQueryVO.getInsurcode()) ? null : Restrictions.like("insurcode", "%" + tVmInsuranceRegisterQueryVO.getInsurcode() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmInsuranceRegisterQueryVO.getPlatenumber()) ? null : Restrictions.like("platenumber", "%" + tVmInsuranceRegisterQueryVO.getPlatenumber() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmInsuranceRegisterQueryVO.getReporter()) ? null : Restrictions.like("reporter", "%" + tVmInsuranceRegisterQueryVO.getReporter() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmInsuranceRegisterQueryVO.getPaidCustomer()) ? null : Restrictions.like("paidCustomer", "%" + tVmInsuranceRegisterQueryVO.getPaidCustomer() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startTime) && ToolKits.isEmpty(endTime)) {
			r7 = Restrictions.between("outdager", startTime, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("outdager", new GregorianCalendar(1700, 1, 1).getTime(), endTime);
		} else if (ToolKits.isNotEmpty(startTime) && ToolKits.isNotEmpty(endTime)) {
			r7 = Restrictions.between("outdager", startTime, endTime);
		}
		Restriction r8 = Restrictions.in("status", new String[] { BussinessConstant.T_VM_INSURANCE_REJECT, BussinessConstant.T_VM_INSURANCE_COMMIT });
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "outdager" }));
		// 执行查询
		List<TVmInsuranceModel> tVmInsuranceModels = tVmInsuranceMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmInsuranceDTO> tVmInsuranceDTOs = new ArrayList<TVmInsuranceDTO>();
		// 循环处理
		for (TVmInsuranceModel tVmInsuranceModel : tVmInsuranceModels) {
			// 响应对象
			TVmInsuranceDTO tVmInsuranceDTO = new TVmInsuranceDTO();
			BeanUtils.copyProperties(tVmInsuranceModel, tVmInsuranceDTO);

			// 添加响应对象
			tVmInsuranceDTOs.add(tVmInsuranceDTO);
		}
		// 重组分页属性，保证DTO分页正确
		Page<TVmInsuranceDTO> page = PageUtils.getPage(tVmInsuranceDTOs);
		if (tVmInsuranceModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmInsuranceModel> p0 = (com.github.pagehelper.Page<TVmInsuranceModel>) tVmInsuranceModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	// 车辆保险登记保存
	@Override
	public void tVmInsuranceSave(TVmInsuranceVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		if (ToolKits.isEmpty(vo.getBranchId())) {
			throw new ParameterException("机构不能为空！");
		}
		if (ToolKits.isEmpty(vo.getInsurcode())) {
			throw new ParameterException("保险单号不能为空！");
		}
		if (ToolKits.isEmpty(vo.getOutdager())) {
			throw new ParameterException("出现日期不能为空！");
		}
		if (ToolKits.isEmpty(vo.getReportno())) {
			throw new ParameterException("报案编号不能为空！");
		}
		if (ToolKits.isEmpty(vo.getPlatenumber())) {
			throw new ParameterException("车牌号不能为空！");
		}
		if (ToolKits.isEmpty(vo.getReporter())) {
			throw new ParameterException("报案人不能为空！");
		}
		if (ToolKits.isEmpty(vo.getAscriptionCompanyNo())) {
			throw new ParameterException("车辆归属单位不能为空！");
		}
		if (ToolKits.isEmpty(vo.getAscriptionCompanyName())) {
			throw new ParameterException("车辆归属单位名称不能为空！");
		}
		if (ToolKits.isEmpty(vo.getDutyman())) {
			throw new ParameterException("责任人不能为空！");
		}
		if (ToolKits.isEmpty(vo.getResppro())) {
			throw new ParameterException("责任属性不能为空！");
		}
		if (ToolKits.isEmpty(vo.getAmountdam())) {
			throw new ParameterException("定损金额不能为空！");
		}
		if (ToolKits.isEmpty(vo.getPaidCustomer())) {
			throw new ParameterException("赔付单位/个人不能为空！");
		}
		if (ToolKits.isEmpty(vo.getAmountcomp())) {
			throw new ParameterException("应赔付金额不能为空！");
		}
		if (ToolKits.isEmpty(vo.getAmountact())) {
			throw new ParameterException("实际赔付金额不能为空！");
		}

		Criteria criteria = Criteria.forClass(TVmInsuranceModel.class);
		Restriction r1 = ToolKits.isEmpty(vo.getInsurcode()) ? null : Restrictions.eq("insurcode", vo.getInsurcode());
		criteria.setRestriction(Restrictions.and(r1));
		List<TVmInsuranceModel> list = tVmInsuranceMapper.findByCriteria(criteria);
		if (!CollectionUtils.isEmpty(list)) {
			throw new RuntimeException("保险单号已存在！");
		}
		TVmInsuranceModel model = new TVmInsuranceModel();
		BeanUtils.copyProperties(vo, model);
		model.setCreateperson(user.getNickname());
		model.setCreatetime(new Date());
		model.setStatus(BussinessConstant.T_VM_INSURANCE_COMMIT);
		tVmInsuranceMapper.save(model);
	}

	// 车辆保险修改
	@Override
	public void tVmInsuranceUpdate(TVmInsuranceVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		ToolKits.isParamNull(vo, "参数不能为空！");
		ToolKits.isParamNull(vo.getInsurcode(), "保险单号不能为空！");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("branchid", vo.getBranchId());
		map.put("branchname", vo.getBranchname());
		map.put("reportno", vo.getReportno());
		map.put("outdager", vo.getOutdager());
		map.put("platenumber", vo.getPlatenumber());
		map.put("reporter", vo.getReporter());
		map.put("ascriptionCompanyNo", vo.getAscriptionCompanyNo());
		map.put("ascriptionCompanyName", vo.getAscriptionCompanyName());
		map.put("nonOperational", vo.getNonOperational());
		map.put("insurctype", vo.getInsurctype());
		map.put("dutyman", vo.getDutyman());
		map.put("resppro", vo.getResppro());
		map.put("amountdam", vo.getAmountdam());
		map.put("paidCustomer", vo.getPaidCustomer());
		map.put("amountcomp", vo.getAmountcomp());
		map.put("amountact", vo.getAmountact());
		map.put("memo", vo.getMemo());
		map.put("updateperson", user.getNickname());
		map.put("updatetime", new Date());
		map.put("status", BussinessConstant.T_VM_INSURANCE_COMMIT);
		tVmInsuranceMapper.updateMapById(vo.getInsurcode(), map, TVmInsuranceModel.class);
	}

	// 车辆保险删除
	@Override
	public void tVmInsuranceDelete(List<TVmInsuranceVO> vos) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		ToolKits.isParamNull(vos, "参数不能为空！");

		String[] ids = new String[vos.size()];
		int i = 0;
		for (TVmInsuranceVO vo : vos) {
			ids[i] = vo.getInsurcode();
			i++;
		}
		if (ids.length > 0) {
			tVmInsuranceMapper.deleteByIds(ids, TVmInsuranceModel.class);
		}
	}

	// 车辆保险审核
	@Override
	public void tVmInsuranceAudit(TVmInsuranceVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		ToolKits.isParamNull(vo.getInsurcode(), "保险单号不能为空！");
		TVmInsuranceModel model = tVmInsuranceMapper.findById(vo.getInsurcode(), TVmInsuranceModel.class);
		model.setStatus(BussinessConstant.T_VM_INSURANCE_AUDIT);
		model.setAudittime(new Date());
		model.setAuditperson(user.getNickname());
		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(new Date());
		model.setAuditdescrible(vo.getAuditdescrible());
		tVmInsuranceMapper.update(model);
	}

	// 车辆保险驳回
	@Override
	public void tVmInsuranceReject(TVmInsuranceVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		if (ToolKits.isEmpty(vo.getAuditdescrible())) {
			throw new ParameterException("审核意见不能为空！");
		}
		ToolKits.isParamNull(vo.getInsurcode(), "保险单号不能为空！");
		TVmInsuranceModel model = tVmInsuranceMapper.findById(vo.getInsurcode(), TVmInsuranceModel.class);
		model.setStatus(BussinessConstant.T_VM_INSURANCE_REJECT);
		model.setAudittime(new Date());
		model.setAuditperson(user.getNickname());
		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(new Date());
		model.setAuditdescrible(vo.getAuditdescrible());
		tVmInsuranceMapper.update(model);
	}

	/*
	 * 车辆加油查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmFuelRecordDTO> listTVmFuelRecordData(TVmFuelRecordQueryVO tVmFuelRecordQueryVO) {
		ToolKits.isParamNull(tVmFuelRecordQueryVO, "车辆加油查询请求参数不为空");
		ToolKits.isParamNull(tVmFuelRecordQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmFuelRecordQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startdate = tVmFuelRecordQueryVO.getStartdate();
		// 结束时间
		Date enddate = tVmFuelRecordQueryVO.getEnddate();

		PageUtils.startPage(tVmFuelRecordQueryVO.getPageNum(), tVmFuelRecordQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmFuelRecordModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmFuelRecordQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmFuelRecordQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmFuelRecordQueryVO.getBillno()) ? null : Restrictions.like("billno", "%" + tVmFuelRecordQueryVO.getBillno() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmFuelRecordQueryVO.getPlatenumber()) ? null : Restrictions.like("platenumber", "%" + tVmFuelRecordQueryVO.getPlatenumber() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmFuelRecordQueryVO.getOilPerson()) ? null : Restrictions.like("oilPerson", "%" + tVmFuelRecordQueryVO.getOilPerson() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmFuelRecordQueryVO.getGsCode()) ? null : Restrictions.like("gsCode", "%" + tVmFuelRecordQueryVO.getGsCode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startdate) && ToolKits.isEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", startdate, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", new GregorianCalendar(1700, 1, 1).getTime(), enddate);
		} else if (ToolKits.isNotEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", startdate, enddate);
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7));
		criteria.setOrder(Order.newInstance().desc(new String[] { "oilDate" }));
		// 执行查询
		List<TVmFuelRecordModel> tVmFuelRecordModels = tVmFuelRecordMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmFuelRecordDTO> tVmFuelRecordDTOs = new ArrayList<TVmFuelRecordDTO>();
		// 循环处理
		for (TVmFuelRecordModel tVmFuelRecordModel : tVmFuelRecordModels) {
			// 响应对象
			TVmFuelRecordDTO tVmFuelRecordDTO = new TVmFuelRecordDTO();
			BeanUtils.copyProperties(tVmFuelRecordModel, tVmFuelRecordDTO);

			// 添加响应对象
			tVmFuelRecordDTOs.add(tVmFuelRecordDTO);
		}

		// 重组分页属性，保证DTO分页正确
		Page<TVmFuelRecordDTO> page = PageUtils.getPage(tVmFuelRecordDTOs);
		if (tVmFuelRecordModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmFuelRecordModel> p0 = (com.github.pagehelper.Page<TVmFuelRecordModel>) tVmFuelRecordModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆加油审核查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmFuelRecordDTO> listTVmFuelRecordAuditData(TVmFuelRecordAuditQueryVO tVmFuelRecordAuditQueryVO) {
		ToolKits.isParamNull(tVmFuelRecordAuditQueryVO, "车辆加油审核查询请求参数不为空");
		ToolKits.isParamNull(tVmFuelRecordAuditQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmFuelRecordAuditQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startdate = tVmFuelRecordAuditQueryVO.getStartdate();
		// 结束时间
		Date enddate = tVmFuelRecordAuditQueryVO.getEnddate();

		PageUtils.startPage(tVmFuelRecordAuditQueryVO.getPageNum(), tVmFuelRecordAuditQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmFuelRecordModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmFuelRecordAuditQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmFuelRecordAuditQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmFuelRecordAuditQueryVO.getBillno()) ? null : Restrictions.like("billno", "%" + tVmFuelRecordAuditQueryVO.getBillno() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmFuelRecordAuditQueryVO.getPlatenumber()) ? null : Restrictions.like("platenumber", "%" + tVmFuelRecordAuditQueryVO.getPlatenumber() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmFuelRecordAuditQueryVO.getOilPerson()) ? null : Restrictions.like("oilPerson", "%" + tVmFuelRecordAuditQueryVO.getOilPerson() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmFuelRecordAuditQueryVO.getGsCode()) ? null : Restrictions.like("gsCode", "%" + tVmFuelRecordAuditQueryVO.getGsCode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startdate) && ToolKits.isEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", startdate, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", new GregorianCalendar(1700, 1, 1).getTime(), enddate);
		} else if (ToolKits.isNotEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", startdate, enddate);
		}
		Restriction r8 = Restrictions.eq("status", BussinessConstant.TMS_REPAIR_RECORD_COMMIT);
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "oilDate" }));
		// 执行查询
		List<TVmFuelRecordModel> tVmFuelRecordModels = tVmFuelRecordMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmFuelRecordDTO> tVmFuelRecordDTOs = new ArrayList<TVmFuelRecordDTO>();
		// 循环处理
		for (TVmFuelRecordModel tVmFuelRecordModel : tVmFuelRecordModels) {
			// 响应对象
			TVmFuelRecordDTO tVmFuelRecordDTO = new TVmFuelRecordDTO();
			BeanUtils.copyProperties(tVmFuelRecordModel, tVmFuelRecordDTO);

			// 添加响应对象
			tVmFuelRecordDTOs.add(tVmFuelRecordDTO);
		}

		// 重组分页属性，保证DTO分页正确
		Page<TVmFuelRecordDTO> page = PageUtils.getPage(tVmFuelRecordDTOs);
		if (tVmFuelRecordModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmFuelRecordModel> p0 = (com.github.pagehelper.Page<TVmFuelRecordModel>) tVmFuelRecordModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/*
	 * 车辆加油登记查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<TVmFuelRecordDTO> listTVmFuelRecordRegisterData(TVmFuelRecordRegisterQueryVO tVmFuelRecordRegisterQueryVO) {
		ToolKits.isParamNull(tVmFuelRecordRegisterQueryVO, "车辆加油登记查询请求参数不为空");
		ToolKits.isParamNull(tVmFuelRecordRegisterQueryVO.getPageNum(), "当前页不为空");
		ToolKits.isParamNull(tVmFuelRecordRegisterQueryVO.getPageSize(), "页面大小不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 开始时间
		Date startdate = tVmFuelRecordRegisterQueryVO.getStartdate();
		// 结束时间
		Date enddate = tVmFuelRecordRegisterQueryVO.getEnddate();

		PageUtils.startPage(tVmFuelRecordRegisterQueryVO.getPageNum(), tVmFuelRecordRegisterQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TVmFuelRecordModel.class);
		Restriction r1 = Restrictions.in("branchid", user.getWarehouses().toArray());
		Restriction r2 = ToolKits.isEmpty(tVmFuelRecordRegisterQueryVO.getBranchId()) ? null : Restrictions.eq("branchid", tVmFuelRecordRegisterQueryVO.getBranchId());
		Restriction r3 = ToolKits.isEmpty(tVmFuelRecordRegisterQueryVO.getBillno()) ? null : Restrictions.like("billno", "%" + tVmFuelRecordRegisterQueryVO.getBillno() + "%");
		Restriction r4 = ToolKits.isEmpty(tVmFuelRecordRegisterQueryVO.getPlatenumber()) ? null : Restrictions.like("platenumber", "%" + tVmFuelRecordRegisterQueryVO.getPlatenumber() + "%");
		Restriction r5 = ToolKits.isEmpty(tVmFuelRecordRegisterQueryVO.getOilPerson()) ? null : Restrictions.like("oilPerson", "%" + tVmFuelRecordRegisterQueryVO.getOilPerson() + "%");
		Restriction r6 = ToolKits.isEmpty(tVmFuelRecordRegisterQueryVO.getGsCode()) ? null : Restrictions.like("gsCode", "%" + tVmFuelRecordRegisterQueryVO.getGsCode() + "%");
		Restriction r7 = null;
		if (ToolKits.isNotEmpty(startdate) && ToolKits.isEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", startdate, new GregorianCalendar(3000, 1, 1).getTime());
		} else if (ToolKits.isEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", new GregorianCalendar(1700, 1, 1).getTime(), enddate);
		} else if (ToolKits.isNotEmpty(startdate) && ToolKits.isNotEmpty(enddate)) {
			r7 = Restrictions.between("oilDate", startdate, enddate);
		}
		Restriction r8 = Restrictions.in("status", new String[] { BussinessConstant.T_VM_FUEL_RECORD_REJECT, BussinessConstant.T_VM_FUEL_RECORD_COMMIT });
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8));
		criteria.setOrder(Order.newInstance().desc(new String[] { "oilDate" }));
		// 执行查询
		List<TVmFuelRecordModel> tVmFuelRecordModels = tVmFuelRecordMapper.findByCriteria(criteria);

		// 响应对象集合
		List<TVmFuelRecordDTO> tVmFuelRecordDTOs = new ArrayList<TVmFuelRecordDTO>();
		// 循环处理
		for (TVmFuelRecordModel tVmFuelRecordModel : tVmFuelRecordModels) {
			// 响应对象
			TVmFuelRecordDTO tVmFuelRecordDTO = new TVmFuelRecordDTO();
			BeanUtils.copyProperties(tVmFuelRecordModel, tVmFuelRecordDTO);

			// 添加响应对象
			tVmFuelRecordDTOs.add(tVmFuelRecordDTO);
		}

		// 重组分页属性，保证DTO分页正确
		Page<TVmFuelRecordDTO> page = PageUtils.getPage(tVmFuelRecordDTOs);
		if (tVmFuelRecordModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TVmFuelRecordModel> p0 = (com.github.pagehelper.Page<TVmFuelRecordModel>) tVmFuelRecordModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	// 车辆加油登记
	@Override
	public void tVmFuelRecordSave(TVmFuelRecordVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		ToolKits.isParamNull(vo, "参数不能为空！");
		ToolKits.isParamNull(vo.getBillno(), "加油单号不能为空！");

		Criteria criteria = Criteria.forClass(TVmFuelRecordModel.class);
		Restriction r1 = Restrictions.eq("billno", vo.getBillno());
		criteria.setRestriction(Restrictions.and(r1));
		List<TVmFuelRecordModel> list = tVmFuelRecordMapper.findByCriteria(criteria);
		if (!CollectionUtils.isEmpty(list)) {
			throw new RuntimeException("加油单号已存在！");
		}
		TVmFuelRecordModel model = new TVmFuelRecordModel();
		BeanUtils.copyProperties(vo, model);
		model.setCreateperson(user.getNickname());
		model.setCreatetime(new Date());
		model.setStatus(BussinessConstant.T_VM_FUEL_RECORD_COMMIT);
		tVmFuelRecordMapper.save(model);
	}

	// 车辆加油修改
	@Override
	public void tVmFuelRecordUpdate(TVmFuelRecordVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		ToolKits.isParamNull(vo, "参数不能为空！");
		ToolKits.isParamNull(vo.getBillno(), "加油单号不能为空！");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("branchid", vo.getBranchId());
		map.put("branchname", vo.getBranchname());
		map.put("platenumber", vo.getPlatenumber());
		map.put("gsCode", vo.getGsCode());
		map.put("gsName", vo.getGsName());
		map.put("oiltype", vo.getOiltype());
		map.put("oilPrice", vo.getOilPrice());
		map.put("oilDate", vo.getOilDate());
		map.put("oilPerson", vo.getOilPerson());
		map.put("oilQuantity", vo.getOilQuantity());
		map.put("odometer", vo.getOdometer());
		map.put("amount", vo.getAmount());
		map.put("memo", vo.getMemo());
		map.put("updateperson", user.getNickname());
		map.put("updatetime", new Date());
		map.put("status", BussinessConstant.T_VM_FUEL_RECORD_COMMIT);
		tVmFuelRecordMapper.updateMapById(vo.getBillno(), map, TVmFuelRecordModel.class);
	}

	// 车辆加油删除
	@Override
	public void tVmFuelRecordDelete(List<TVmFuelRecordVO> vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		if (ToolKits.isEmpty(vo)) {
			throw new ParameterException("参数不能为空！");
		}
		String[] ids = new String[vo.size()];
		int i = 0;
		for (TVmFuelRecordVO tVmFuelRecordVo : vo) {
			ids[i] = tVmFuelRecordVo.getBillno();
			i++;
		}
		if (ids.length > 0) {
			tVmFuelRecordMapper.deleteByIds(ids, TVmFuelRecordModel.class);
		}
	}

	// 车辆加油审核
	@Override
	public void tVmFuelRecordAudit(TVmFuelRecordVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		ToolKits.isParamNull(vo, "参数不能为空！");

		TVmFuelRecordModel model = tVmFuelRecordMapper.findById(vo.getBillno(), TVmFuelRecordModel.class);
		model.setStatus(BussinessConstant.T_VM_FUEL_RECORD_AUDIT);
		model.setAudittime(new Date());
		model.setAuditdescrible(vo.getAuditdescrible());
		model.setAuditperson(user.getNickname());
		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(new Date());
		tVmFuelRecordMapper.update(model);
	}

	// 车辆加油驳回
	@Override
	public void tVmFuelRecordReject(TVmFuelRecordVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "没有操作权限！");
		ToolKits.isParamNull(vo, "参数不能为空！");
		ToolKits.isParamNull(vo.getAuditdescrible(), "审核意见不能为空！");

		TVmFuelRecordModel model = tVmFuelRecordMapper.findById(vo.getBillno(), TVmFuelRecordModel.class);
		model.setStatus(BussinessConstant.T_VM_FUEL_RECORD_REJECT);
		model.setAudittime(new Date());
		model.setAuditdescrible(vo.getAuditdescrible());
		model.setAuditperson(user.getNickname());
		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(new Date());
		tVmFuelRecordMapper.update(model);
	}
}
