yonge 5 лет назад
Родитель
Сommit
f56c6855ce

+ 5 - 0
cms/src/main/java/com/ym/mec/cms/dal/dao/SysNewsInformationDao.java

@@ -1,6 +1,7 @@
 package com.ym.mec.cms.dal.dao;
 
 import java.util.List;
+import java.util.Map;
 
 import com.ym.mec.cms.dal.entity.SysNewsInformation;
 import com.ym.mec.common.dal.BaseDAO;
@@ -20,4 +21,8 @@ public interface SysNewsInformationDao extends BaseDAO<Long, SysNewsInformation>
 	 * @return
 	 */
 	int deleteWithLogical(Long id);
+	
+	List<SysNewsInformation> queryHomePage(Map<String, Object> params);
+	
+	int queryHomeCount(Map<String, Object> params);
 }

+ 28 - 7
cms/src/main/java/com/ym/mec/cms/service/impl/SysNewsInformationServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ym.mec.cms.service.impl;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -7,6 +8,7 @@ import java.util.Map;
 import com.ym.mec.cms.controller.queryinfo.NewsInformationQueryInfo;
 import com.ym.mec.cms.dal.entity.NewsStatusEnum;
 import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.page.QueryInfo;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -52,28 +54,47 @@ public class SysNewsInformationServiceImpl extends BaseServiceImpl<Long, SysNews
 		MapUtil.populateMap(params, queryInfo);
 
 		queryInfo.setType(3);
-		int count = sysNewsInformationDao.queryCount(params);
+		int count = sysNewsInformationDao.queryHomeCount(params);
 		if(count == 0){
 			queryInfo.setMemo(null);
 		}
-		homeList.put("banner",queryPage(queryInfo));
+		homeList.put("banner",queryHomePage(queryInfo));
 		
 		queryInfo.setMemo(memo);
 		queryInfo.setType(6);
-		count = sysNewsInformationDao.queryCount(params);
+		count = sysNewsInformationDao.queryHomeCount(params);
 		if(count == 0){
 			queryInfo.setMemo(null);
 		}
-		homeList.put("app",queryPage(queryInfo));
+		homeList.put("app",queryHomePage(queryInfo));
 		
 		queryInfo.setMemo(null);
 		queryInfo.setType(1);
-		homeList.put("active",queryPage(queryInfo));
+		homeList.put("active",queryHomePage(queryInfo));
 		queryInfo.setType(2);
-		homeList.put("hot",queryPage(queryInfo));
+		homeList.put("hot",queryHomePage(queryInfo));
 		queryInfo.setType(5);
-		homeList.put("flash",queryPage(queryInfo));
+		homeList.put("flash",queryHomePage(queryInfo));
 		return homeList;
 	}
+	
+	private PageInfo<SysNewsInformation> queryHomePage(QueryInfo queryInfo) {
+		PageInfo<SysNewsInformation> pageInfo = new PageInfo<SysNewsInformation>(queryInfo.getPage(), queryInfo.getRows());
+		Map<String, Object> params = new HashMap<String, Object>();
+		MapUtil.populateMap(params, queryInfo);
+		
+		List<SysNewsInformation> dataList = null;
+		int count = sysNewsInformationDao.queryHomeCount(params);
+		if (count > 0) {
+			pageInfo.setTotal(count);
+			params.put("offset", pageInfo.getOffset());
+			dataList = sysNewsInformationDao.queryHomePage(params);
+		}
+		if (count == 0) {
+			dataList = new ArrayList<SysNewsInformation>();
+		}
+		pageInfo.setRows(dataList);
+		return pageInfo;
+	}
 
 }

+ 55 - 8
cms/src/main/resources/config/mybatis/SysNewsInformationMapper.xml

@@ -37,14 +37,6 @@
 			<if test="search != null">
 				and title_ like '%' #{search} '%'
 			</if>
-			<choose>
-		        <when test="memo != null and memo != ''">
-		            and memo_ = #{memo}
-		        </when>
-		        <otherwise>
-		            and memo_ is null
-		        </otherwise>
-		    </choose>
 		</where>
 	</sql>
 	
@@ -137,4 +129,59 @@
 	<update id="deleteWithLogical">
 		UPDATE sys_news_information SET del_flag_ = 1,update_time_ = NOW() WHERE id_ = #{id}
 	</update>
+	
+	<!-- 分页查询 -->
+	<select id="queryHomePage" resultMap="SysNewsInformation"
+		parameterType="map">
+		SELECT * FROM sys_news_information where del_flag_=0
+		<if test="type != null">
+			and type_ = #{type}
+		</if>
+		<if test="status != null">
+			and status_ = #{status,
+			typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+		</if>
+		<if test="title != null">
+			and title_ like '%' #{title} '%'
+		</if>
+		<if test="search != null">
+			and title_ like '%' #{search} '%'
+		</if>
+		<choose>
+			<when test="memo != null and memo != ''">
+				and memo_ = #{memo}
+			</when>
+			<otherwise>
+				and memo_ is null
+			</otherwise>
+		</choose>
+		order by order_ desc,update_time_ desc
+		<include refid="global.limit" />
+	</select>
+
+	<!-- 查询当前表的总记录数 -->
+	<select id="queryHomeCount" resultType="int">
+		SELECT COUNT(*) FROM sys_news_information where del_flag_=0
+		<if test="type != null">
+			and type_ = #{type}
+		</if>
+		<if test="status != null">
+			and status_ = #{status,
+			typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+		</if>
+		<if test="title != null">
+			and title_ like '%' #{title} '%'
+		</if>
+		<if test="search != null">
+			and title_ like '%' #{search} '%'
+		</if>
+		<choose>
+			<when test="memo != null and memo != ''">
+				and memo_ = #{memo}
+			</when>
+			<otherwise>
+				and memo_ is null
+			</otherwise>
+		</choose>
+	</select>
 </mapper>