package com.unis.base.server.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.unis.base.common.vo.TyCrkjsxxVO;
import com.unis.base.server.domain.TyCrkjsxxDomain;
import com.unis.base.server.service.TyCrkjsxxService;
import com.unis.common.utils.DateUtil;

/**
 * @author zhengbodang
 * @version 1.0
 * @Title TyCrkjsxxServiceImpl
 * @ProjectName TyCrkjsxxServiceImpl
 * @Description
 * @date 2019/07/22 17点26分
 */
@Service
public class TyCrkjsxxServiceImpl implements TyCrkjsxxService {

	@Autowired
	private TyCrkjsxxDomain tyCrkjsxxDomain;

	/**
	 * 根据参数获取廒间信息
	 * @param dAjxxsjyVO
	 * @return
	 */
	@Override
	public List<TyCrkjsxxVO> getTyCrkjsxxList(TyCrkjsxxVO tyCrkjsxxVO) {
		return tyCrkjsxxDomain.getTyCrkjsxxList(tyCrkjsxxVO);
	}

	/**
	 * 分页获取廒间信息列表
	 * @param dAjxxsjyVO
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@Override
	public List<TyCrkjsxxVO> getTyCrkjsxxPage(TyCrkjsxxVO tyCrkjsxxVO, Integer pageNum, Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		return tyCrkjsxxDomain.getTyCrkjsxxList(tyCrkjsxxVO);
	}

	/**
	 * 添加廒间信息
	 * @param dAjxxsjyVO
	 * @return
	 */
	@Override
	public int insert(TyCrkjsxxVO tyCrkjsxxVO) {
		String date = DateUtil.getCurrentDateTime16Str();
		String currentStringTimestamp = DateUtil.getCurrentStringTimestamp();
		tyCrkjsxxVO.setJsid("JS"+date);
		tyCrkjsxxVO.setJsdh(currentStringTimestamp);
		return tyCrkjsxxDomain.insert(tyCrkjsxxVO);
	}

	/**
	 * 更新廒间信息
	 * @param dAjxxsjyVO
	 * @return
	 */
	@Override
	public int update(TyCrkjsxxVO tyCrkjsxxVO) {
		return tyCrkjsxxDomain.update(tyCrkjsxxVO);
	}

	/**
	 * 删除廒间信息
	 * @param ajbh 廒间编号
	 * @return
	 */
	@Override
	public int delete(String jsid) {
		//根据廒间编号获取廒间信息
		TyCrkjsxxVO dAjxxsjyVO = tyCrkjsxxDomain.getTyCrkjsxxById(jsid);
		if(dAjxxsjyVO == null) {//廒间不存在
			return -1;
		}

		dAjxxsjyVO.setStatus(0);
		return tyCrkjsxxDomain.update(dAjxxsjyVO);
	}

	/**
	 * 根据廒间编号获取廒间信息
	 * @param ajbh 廒间编号
	 * @return
	 */
	@Override
	public TyCrkjsxxVO getTyCrkjsxxByJsid(String jsid) {
		return tyCrkjsxxDomain.getTyCrkjsxxById(jsid);
	}


}
