package com.kede.news.service.impl; import java.text.ParseException; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.kede.common.constant.AFTConstants; import com.kede.common.dao.NewsMapper; import com.kede.common.error.BusinessException; import com.kede.common.utils.DateUtils; import com.kede.core.mybatis.BaseMybatisDao; import com.kede.core.mybatis.page.Pagination; import com.kede.news.bo.InputNews; import com.kede.news.bo.OutNews; import com.kede.news.service.NewsService; @Service public class NewsServiceImpl extends BaseMybatisDao implements NewsService { @Autowired private NewsMapper newsMapper; @Override public int addNews(InputNews in) { if (in.getReleaseTimes()!=null) { try { in.setReleaseTime(DateUtils.StringToDate(in.getReleaseTimes(), AFTConstants.YYYYMMDDHHMMSS)); } catch (ParseException e) { throw new BusinessException("转换异常"); } } if (in.getReleaseStatus()==1&&in.getReleaseTime()==null) { in.setReleaseTime(new Date()); } return newsMapper.insertSelective(in); } @Override public int updateNews(InputNews in) { if (in.getReleaseTimes()!=null) { try { in.setReleaseTime(DateUtils.StringToDate(in.getReleaseTimes(), AFTConstants.YYYYMMDDHHMMSS)); } catch (ParseException e) { throw new BusinessException("转换异常"); } } if (in.getReleaseStatus()==1&&in.getReleaseTime()==null) { in.setReleaseTime(new Date()); } return newsMapper.updateByPrimaryKeySelective(in); } @Override public int deleteNews(InputNews in) { return newsMapper.deleteByPrimaryKey(in.getId()); } @SuppressWarnings("unchecked") @Override public Pagination listnewsDetails(InputNews in, Integer pageSize, Integer pageNo) { Map params = new HashMap<>(); if(pageSize==null||pageSize<0)pageSize=10; if(pageNo==null||pageNo<0)pageNo=1; params.put("n", in); return (Pagination) findPage("findNewsList", "findNewsCount", params, pageNo, pageSize); } @Override public OutNews selectNews(InputNews in) { return newsMapper.selectByid(in.getId()); } }