From 0f3913854344bc3496fd36fc778965689e3e50c4 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期一, 25 三月 2019 14:06:01 +0800
Subject: [PATCH] PushRecordDAO改造

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushRecordServiceImpl.java |  100 +++++++++++++------------------------------------
 1 files changed, 27 insertions(+), 73 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushRecordServiceImpl.java
index a6bba98..2995f4e 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushRecordServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/push/PushRecordServiceImpl.java
@@ -1,98 +1,52 @@
 package com.yeshi.fanli.service.impl.push;
 
-import java.io.Serializable;
 import java.util.List;
 
 import javax.annotation.Resource;
 
-import org.hibernate.HibernateException;
-import org.hibernate.SQLQuery;
-import org.hibernate.Session;
-import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
 
-import com.yeshi.fanli.dao.config.PushRecordDao;
+import com.yeshi.fanli.dao.mybatis.push.PushRecordMapper;
 import com.yeshi.fanli.entity.xinge.PushRecord;
 import com.yeshi.fanli.service.inter.push.PushRecordService;
-import com.yeshi.fanli.util.Constant;
 @Service
 public class PushRecordServiceImpl implements PushRecordService {
 	
 	@Resource
-	private PushRecordDao dao;
+	private PushRecordMapper pushRecordMapper;
 
-	public void save(PushRecord pushRecord) {
-		pushRecord.setCreatetime(System.currentTimeMillis());
-		dao.save(pushRecord);
+
+	public List<PushRecord> getPushRecordList(long start, int pageSize,String key, int type) {
+		return pushRecordMapper.listQuery(start, pageSize, key, type);
 	}
 
-	public List<PushRecord> getPushRecordList(String title, int type, int page) {
-		int start = (page-1) * Constant.PAGE_SIZE;
-		StringBuffer hqlBuf=new StringBuffer("from PushRecord pr where 1=1 ");
-		
-		if(title !=null && !"".equals(title.trim())){
-			hqlBuf.append(" and (pr.title like ? )");
-		}
-		if(type != 0){
-			hqlBuf.append(" and (pr.type = ? )");
-		}
-		hqlBuf.append(" order by pr.id desc ");
-		String hql = hqlBuf.toString();
-		if(hql.contains("pr.title") && hql.contains("pr.type")){
-			return dao.list(hqlBuf.toString(), start, Constant.PAGE_SIZE, new Serializable[]{"%"+title+"%",type});
-		}else if(hql.contains("pr.title") && !hql.contains("pr.type")){
-			return dao.list(hqlBuf.toString(), start, Constant.PAGE_SIZE, new Serializable[]{"%"+title+"%"});
-		}else if(!hql.contains("pr.title") && hql.contains("pr.type")){
-			return dao.list(hqlBuf.toString(), start, Constant.PAGE_SIZE, new Serializable[]{type});
-		}else{
-			return dao.list(hqlBuf.toString(), start, Constant.PAGE_SIZE, new Serializable[]{});
-		}
-		
+	public Long getCount(String title, int type) {
+		return pushRecordMapper.countQuery(title, type);
 	}
 
-	public int getCount(String title, int type, int page) {
-		
-		StringBuffer hqlBuf=new StringBuffer("select count(*) from PushRecord pr where 1=1 ");
-		
-		if(title !=null && !"".equals(title.trim())){
-			hqlBuf.append(" and (pr.title like ? )");
-		}
-		if(type != 0){
-			hqlBuf.append(" and (pr.type = ? )");
-		}
-		String hql = hqlBuf.toString();
-		if(hql.contains("pr.title") && hql.contains("pr.type")){
-			return (int) dao.getCount(hqlBuf.toString(), new Serializable[]{"%"+title+"%",type});
-		}else if(hql.contains("pr.title") && !hql.contains("pr.type")){
-			return (int) dao.getCount(hqlBuf.toString(),new Serializable[]{"%"+title+"%"});
-		}else if(!hql.contains("pr.title") && hql.contains("pr.type")){
-			return (int) dao.getCount(hqlBuf.toString(),new Serializable[]{type});
-		}else{
-			return (int) dao.getCount(hqlBuf.toString(),new Serializable[]{});
-		}
-	}
-
-	public void increaseByAndroid(final String pushId) {
-		final String sql="update yeshi_ec_push_record pr set pr.count=pr.count+1 where pr.androidPushId = ? ";
-		dao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session)
-					throws HibernateException {
-				SQLQuery query = session.createSQLQuery(sql);
-				query.setParameter(0, pushId);
-				return query.executeUpdate();
+	public void increaseByAndroid(String pushId) {
+		PushRecord pushRecord = pushRecordMapper.getByAndroidPushId(pushId);
+		if (pushRecord != null) {
+			Long count = pushRecord.getCount();
+			if(count == null) {
+				pushRecord.setCount(1L);
+			} else {
+				pushRecord.setCount(count + 1);
 			}
-		});
+			pushRecordMapper.updateByPrimaryKeySelective(pushRecord);
+		}
 	}
 
-	public void increaseByIOS(final String pushId) {
-		final String sql="update yeshi_ec_push_record pr set pr.count=pr.count+1 where pr.iosPushId = ? ";
-		dao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session)
-					throws HibernateException {
-				SQLQuery query = session.createSQLQuery(sql);
-				query.setParameter(0, pushId);
-				return query.executeUpdate();
+	public void increaseByIOS(String pushId) {
+		PushRecord pushRecord = pushRecordMapper.getByIosPushId(pushId);
+		if (pushRecord != null) {
+			Long count = pushRecord.getCount();
+			if(count == null) {
+				pushRecord.setCount(1L);
+			} else {
+				pushRecord.setCount(count + 1);
 			}
-		});
+			pushRecordMapper.updateByPrimaryKeySelective(pushRecord);
+		}
 	}
 }

--
Gitblit v1.8.0