package com.unis.detectionnum.server.domain;

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

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

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.unis.common.utils.LsBeanUtils;
import com.unis.detectionnum.common.vo.AnnouncementVO;
import com.unis.detectionnum.server.dao.AnnouncementDao;
import com.unis.detectionnum.server.entity.AnnouncementDO;

@Component
public class AnnouncementDomain extends BaseDomain{

	@Autowired
    private AnnouncementDao announcementDao;

	/** 
	 * @Title: getAnnouncementPageList 
	 * @Description: TODO
	 * @param paramMap
	 * @param pageNum
	 * @param pageSize
	 * @return PageInfo<AnnouncementVO>
	 * @throws 
	 */
	public PageInfo<AnnouncementVO> getAnnouncementPageList(Map<String, Object> paramMap, Integer pageNum,
			Integer pageSize) {
		
		PageInfo<AnnouncementVO> voPageInfo = new PageInfo<>();
		
		PageHelper.startPage(pageNum, pageSize);
		List<AnnouncementDO> announcementDOs = announcementDao.selectByParams(paramMap);
		PageInfo<AnnouncementDO> doPageInfo = new PageInfo<>(announcementDOs);
		
		LsBeanUtils.copyAllProperties(doPageInfo, voPageInfo);
		return voPageInfo;
	}

	/** 
	 * @Title: saveAnnouncement 
	 * @Description: 发布公告
	 * @param announcementVO
	 * @return int
	 * @throws 
	 */
	public int saveAnnouncement(AnnouncementVO announcementVO) {
		AnnouncementDO announcementDO = new AnnouncementDO();
		if(announcementVO != null) {
			LsBeanUtils.copyAllProperties(announcementVO, announcementDO);
		}
		announcementDO.setPublishDate(new Date());
		return announcementDao.insertSelective(announcementDO);
	}

	/** 
	 * @Title: updateAnnouncement 
	 * @Description: 修改公告
	 * @param announcementVO
	 * @return int
	 * @throws 
	 */
	public int updateAnnouncement(AnnouncementVO announcementVO) {
		AnnouncementDO announcementDO = new AnnouncementDO();
		if(announcementVO != null) {
			LsBeanUtils.copyAllProperties(announcementVO, announcementDO);
		}
		return announcementDao.updateByPrimaryKeySelective(announcementDO);
	}

	/** 
	 * @Title: deleteAnnouncement 
	 * @Description: 删除公告
	 * @param announcementId
	 * @param @return
	 * @return int
	 * @throws 
	 */
	public int deleteAnnouncement(Integer announcementId) {
		
		return announcementDao.deleteByPrimaryKey(announcementId);
	}

	public AnnouncementDO selectByPrimaryKey(Integer announcementId) {
		AnnouncementDO announcementDO = announcementDao.selectByPrimaryKey(announcementId);
		return announcementDO;
	}

}
