package com.unis.base.server.domain;

import com.unis.base.common.vo.CompanyRecordsNewVO;
import com.unis.base.common.vo.CompanyRecordsQueryVO;
import com.unis.base.common.vo.CompanyRecordsVO;
import com.unis.base.server.dao.CompanyRecordsDao;
import com.unis.base.server.entity.CompanyRecordsDO;
import com.unis.common.utils.DateUtil;
import com.unis.common.utils.LsBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @author WangZL
 * @version 1.0
 * @Title CompanyRecordsDomain
 * @ProjectName 持久化
 * @Description
 * @date 2019/07/22 17点26分
 */
@Component
public class CompanyRecordsDomain extends BaseDomain {

	@Autowired
	private CompanyRecordsDao companyRecordsDao;

	/**
	 * 根据参数获取企业记录列表
	 * @param companyRecordsQueryVO
	 * @return
	 */
	public List<CompanyRecordsVO> getCompanyRecordsList(CompanyRecordsQueryVO companyRecordsQueryVO) {
		return companyRecordsDao.getCompanyRecordsList(companyRecordsQueryVO);
	}

	/**
	 * 获取企业记录详情
	 * @param qybabh
	 * @return
	 */
	public CompanyRecordsVO getCompanyRecordsInfo(String qybabh) {
		CompanyRecordsDO companyRecordsDO = companyRecordsDao.getCompanyRecordsInfo(qybabh);
		if (companyRecordsDO == null){
			return  null;
		}
		CompanyRecordsVO companyRecordsVO = new CompanyRecordsVO();
		LsBeanUtils.copyAllProperties(companyRecordsDO, companyRecordsVO);
		return companyRecordsVO;
	}

	/**
	 * 新增企业记录
	 * @param companyRecordsVO
	 * @return
	 */
	public String insert(CompanyRecordsVO companyRecordsVO) {
		//进行信息copy
		CompanyRecordsDO companyRecordsDO = new CompanyRecordsDO();
		//企业备案编号（yyyymmdd+0001）
		String prefix = DateUtil.getDate()+"";
		String qybabh = getMaxCodeById(companyRecordsDao.getMaxById(prefix), prefix, 4);
		companyRecordsVO.setQybabh(qybabh);
		companyRecordsVO.setStatus(1);
		companyRecordsVO.setCreateDate(new Date());
		LsBeanUtils.copyAllProperties(companyRecordsVO, companyRecordsDO);
		int x = companyRecordsDao.insert(companyRecordsDO);
		if (x == 0){
			return null;
		}
		return qybabh;
	}

	/**
	 * 新增企业记录
	 * @param companyRecordsVO
	 * @return
	 */
	//原方法    CompanyVO  qylx  是 数组
	public String insert(CompanyRecordsNewVO companyRecordsVO) {
		//进行信息copy
		CompanyRecordsDO companyRecordsDO = new CompanyRecordsDO();
		//企业备案编号（yyyymmdd+0001）
		String prefix = DateUtil.getDate()+"";
		String qybabh = getMaxCodeById(companyRecordsDao.getMaxById(prefix), prefix, 4);
		companyRecordsVO.setQybabh(qybabh);
		companyRecordsVO.setStatus(1);
		companyRecordsVO.setCreateDate(new Date());
		LsBeanUtils.copyAllProperties(companyRecordsVO, companyRecordsDO);
		int x = companyRecordsDao.insert(companyRecordsDO);
		if (x == 0){
			return null;
		}
		return qybabh;
	}

	/**
	 * 更新企业记录信息
	 * @param companyRecordsVO
	 * @return
	 */
	public int update(CompanyRecordsVO companyRecordsVO) {
		CompanyRecordsDO companyRecordsDO = new CompanyRecordsDO();
		LsBeanUtils.copyAllProperties(companyRecordsVO, companyRecordsDO);
		return companyRecordsDao.update(companyRecordsDO);
	}
}
