package com.yeshi.buwan.service.imp; import java.util.List; import javax.annotation.Resource; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.yeshi.buwan.dao.ShareContentDao; import com.yeshi.buwan.domain.ShareContent; import com.yeshi.buwan.util.Constant; @Service public class ShareService { @Resource private ShareContentDao shareContentDao; /** * 添加分享内容 * * @param sc */ public void addShareContent(ShareContent sc) { shareContentDao.create(sc); } public void updateShareContent(ShareContent sc) { shareContentDao.update(sc); } /** * 获取分享内容 * * @param id * @return */ public ShareContent getShareContentById(String id) { return shareContentDao.find(ShareContent.class, id); } public List getShareContentList(String key, int page) { return shareContentDao.list("from ShareContent sc where sc.detailSystem.appName like ?", (page - 1) * Constant.pageCount, Constant.pageCount, new String[] { "%" + key + "%" }); } public long getShareContentListCount(String key) { return shareContentDao.getCount("select count(*) from ShareContent sc where sc.detailSystem.appName like ?", new String[] { "%" + key + "%" }); } public void deleteShareContent(ShareContent sc) { shareContentDao.delete(sc); } @Cacheable(value="userCache",key="'getShareContent'+'-'+#detailSystem") public ShareContent getShareContent(String detailSystem) { List list = shareContentDao.list("from ShareContent sc where sc.detailSystem.id=" + detailSystem); if (list != null && list.size() > 0) { return list.get(0); } return null; } }