From cdcbed9af813b2a02cdc01eefa24db8bec6b51a9 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期三, 27 三月 2019 12:17:33 +0800
Subject: [PATCH] 主分类 + 子分类 DAO改造

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSecondClassServiceImpl.java |   62 +++++++-----------------------
 1 files changed, 15 insertions(+), 47 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSecondClassServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSecondClassServiceImpl.java
index 2cb3aef..7b0a16a 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSecondClassServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSecondClassServiceImpl.java
@@ -1,17 +1,13 @@
 package com.yeshi.fanli.service.impl.goods;
 
-import java.io.Serializable;
 import java.util.List;
 
 import javax.annotation.Resource;
 
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
 import org.springframework.cache.annotation.Cacheable;
-import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
 
-import com.yeshi.fanli.dao.goods.GoodsSecondClassDao;
+import com.yeshi.fanli.dao.mybatis.GoodsSecondClassMapper;
 import com.yeshi.fanli.entity.bus.clazz.GoodsSecondClass;
 import com.yeshi.fanli.exception.NotExistObjectException;
 import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
@@ -21,55 +17,39 @@
 public class GoodsSecondClassServiceImpl implements GoodsSecondClassService {
 
 	@Resource
-	private GoodsSecondClassDao goodsSecondClassDao;
+	private GoodsSecondClassMapper goodsSecondClassMapper;
+	
+	
+	
 	@Cacheable(value="classCache",key="'getGoodsSecondClassByGoodsClassId-'+#id")
 	public List<GoodsSecondClass> getGoodsSecondClassByGoodsClassId(long id) {
-
-		List<GoodsSecondClass> list = goodsSecondClassDao.list(
-				"from GoodsSecondClass gsc " + "where gsc.parent.id=? order by gsc.orderby ",
-				new Serializable[] { id });
-
-		return list;
+		return goodsSecondClassMapper.getByGoodsClassId(id);
 	}
 
-	public List<GoodsSecondClass> getSecondClassList(int index, String key,
-			long cid) {
-
-		int start = index * Constant.PAGE_SIZE;
-
-		List<GoodsSecondClass> list = goodsSecondClassDao
-				.list("from GoodsSecondClass gsc where gsc.parent.id=? and gsc.name like ? order by gsc.orderby",
-						start, Constant.PAGE_SIZE, new Serializable[] { cid,
-								"%" + key + "%" });
-
-		return list;
+	public List<GoodsSecondClass> getSecondClassList(int index, String key,	long cid) {
+		return goodsSecondClassMapper.getByNameAndGoodsClassId(index * Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid, key);
 	}
 
 	public int getCount(long cid, String key) {
-		Long lcount = goodsSecondClassDao
-				.getCount(
-						"select count(*) from GoodsSecondClass gsc where gsc.parent.id=? and gsc.name like ? ",
-						new Serializable[] { cid, "%" + key + "%" });
-		return lcount.intValue();
+		return goodsSecondClassMapper.countByNameAndGoodsClassId(cid, key);
 	}
 
 	public void addSecondClass(GoodsSecondClass secondClass) {
 		secondClass.setCreatetime(System.currentTimeMillis());
-		goodsSecondClassDao.save(secondClass);
+		goodsSecondClassMapper.insert(secondClass);
 	}
 
 	public void deleteSecondClass(long sid) {
-		goodsSecondClassDao.delete(new GoodsSecondClass(sid));
+		goodsSecondClassMapper.deleteByPrimaryKey(sid);
 	}
 
 	public GoodsSecondClass getSecondClass(long scid) {
-		return goodsSecondClassDao.find(GoodsSecondClass.class, scid);
+		return goodsSecondClassMapper.selectByPrimaryKey(scid);
 	}
-
+	
 	public void updateSecondClass(GoodsSecondClass secondClass)
 			throws NotExistObjectException {
-		GoodsSecondClass find = goodsSecondClassDao.find(
-				GoodsSecondClass.class, secondClass.getId());
+		GoodsSecondClass find = goodsSecondClassMapper.selectByPrimaryKey(secondClass.getId());
 		if (find == null) {
 			throw new NotExistObjectException("涓嶅瓨鍦ㄨ鐢ㄦ埛");
 		}
@@ -77,19 +57,7 @@
 		find.setPicture(secondClass.getPicture());
 		find.setOrderby(secondClass.getOrderby());
 		find.setKey(secondClass.getKey());
-		goodsSecondClassDao.update(find);
-	}
-
-	public void deleteSecondClassByGC(final long id) {
-		goodsSecondClassDao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session)
-					throws HibernateException {
-				session.createQuery(
-						"delete from GoodsSecondClass gsc where gsc.parent.id=?")
-						.setParameter(0, id).executeUpdate();
-				return null;
-			}
-		});
+		goodsSecondClassMapper.updateByPrimaryKey(find);
 	}
 
 }

--
Gitblit v1.8.0