fanli/src/main/java/com/yeshi/fanli/controller/admin/HotSearchAdminController.java
@@ -155,12 +155,8 @@ return; } Integer type = hotSearchService.deleteHotSearch(hsids); if(type==null){ JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功")); }else{ JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败")); } hotSearchService.deleteHotSearch(hsids); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("删除成功")); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败")); @@ -186,14 +182,11 @@ data.put("check", 1); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } else { Integer count = superHotSearchService.deleteSuper(id, systemId); if (count > 0) { JSONObject data = new JSONObject(); data.put("check", 0); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } else { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("修改失败")); } superHotSearchService.deleteSuper(id, systemId); JSONObject data = new JSONObject(); data.put("check", 0); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } } catch (Exception e) { fanli/src/main/java/com/yeshi/fanli/dao/goods/HotSearchDao.java
File was deleted fanli/src/main/java/com/yeshi/fanli/dao/goods/SuperHotSearchDao.java
File was deleted fanli/src/main/java/com/yeshi/fanli/dao/mybatis/goods/HotSearchMapper.java
New file @@ -0,0 +1,29 @@ package com.yeshi.fanli.dao.mybatis.goods; import java.util.List; import org.apache.ibatis.annotations.Param; import com.yeshi.fanli.dao.BaseMapper; import com.yeshi.fanli.entity.bus.search.HotSearch; public interface HotSearchMapper extends BaseMapper<HotSearch>{ /** * 查询 * @param start * @param count * @param key * @param systemId * @return */ List<HotSearch> listQuery(@Param("start") long start, @Param("count") int count, @Param("key") String key, @Param("systemId")Long systemId); /** * 查询统计 * @param key * @param systemId * @return */ int countQuery(@Param("key") String key, @Param("systemId")Long systemId); } fanli/src/main/java/com/yeshi/fanli/dao/mybatis/goods/SuperHotSearchMapper.java
New file @@ -0,0 +1,52 @@ package com.yeshi.fanli.dao.mybatis.goods; import java.util.List; import org.apache.ibatis.annotations.Param; import com.yeshi.fanli.dao.BaseMapper; import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch; public interface SuperHotSearchMapper extends BaseMapper<SuperHotSearch>{ /** * 查询根据系统id * @param start * @param count * @param key * @param systemId * @return */ List<SuperHotSearch> listBySystemId(@Param("systemId")Long systemId); /** * 查询搜索 * @param start * @param count * @param key * @param systemId * @return */ List<SuperHotSearch> listByHotSearchListID(@Param("list")List<Long> list); /** * 查询根据系统id 和 热门词id * @param start * @param count * @param key * @param systemId * @return */ List<SuperHotSearch> listBySystemIdAndHotSearchId(@Param("hid")Long hid, @Param("systemId")Long systemId); /** * 根据id +系统id删除 * @param systemId * @param hid */ void deleteBySystemIdAndHotSearchId(@Param("hid")Long hid, @Param("systemId")Long systemId); } fanli/src/main/java/com/yeshi/fanli/entity/bus/search/HistorySearch.java
@@ -11,13 +11,17 @@ public class HistorySearch { @Column(name="id") private Long id; @Column(name="name") @Expose private String name; @Column(name="businessId") private String businessId; @Column(name="state") private int state; @Column(name="createtime") private Date createtime; fanli/src/main/java/com/yeshi/fanli/entity/bus/search/HotSearch.java
@@ -3,32 +3,27 @@ import java.io.Serializable; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; import org.yeshi.utils.mybatis.Column; import org.yeshi.utils.mybatis.Table; import com.yeshi.fanli.entity.system.BusinessSystem; @Entity @Table(name = "yeshi_ec_hot_search") @Table("yeshi_ec_hot_search") public class HotSearch implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; @Column(name = "`orderby`") private Integer orderby; @Column(name = "`name`") @Column(name = "name") private String name; private Long createtime; @Transient // 系统关联列表 private List<BusinessSystem> systemList; fanli/src/main/java/com/yeshi/fanli/entity/bus/su/search/SuperHotSearch.java
@@ -2,22 +2,14 @@ import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.yeshi.utils.mybatis.Column; import org.yeshi.utils.mybatis.Table; import com.yeshi.fanli.entity.bus.search.HotSearch; import com.yeshi.fanli.entity.system.BusinessSystem; @Entity @Table(name="yeshi_ec_super_hot_search") @Table("yeshi_ec_super_hot_search") public class SuperHotSearch implements Serializable{ /** @@ -25,17 +17,13 @@ */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; @JoinColumn(name="system_id") @ManyToOne(fetch = FetchType.EAGER) @Column(name="system_id") private BusinessSystem system; @JoinColumn(name="hotSearch_id") @ManyToOne(fetch = FetchType.EAGER) @Column(name="hotSearch_id") private HotSearch hotSearch; public SuperHotSearch() { fanli/src/main/java/com/yeshi/fanli/mapping/goods/HotSearchMapper.xml
New file @@ -0,0 +1,60 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yeshi.fanli.dao.mybatis.goods.HotSearchMapper"> <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.search.HotSearch"> <id column="id" property="id" jdbcType="BIGINT"/> <result column="orderby" property="orderby" jdbcType="INTEGER"/> <result column="name" property="name" jdbcType="VARCHAR"/> </resultMap> <sql id="Base_Column_List">id,`orderby`,`name`</sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> select <include refid="Base_Column_List"/>from yeshi_ec_hot_search where id = #{id,jdbcType=BIGINT} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_hot_search where id = #{id,jdbcType=BIGINT}</delete> <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.search.HotSearch" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_hot_search (id,`orderby`,`name`) values (#{id,jdbcType=BIGINT},#{orderby,jdbcType=INTEGER},#{name,jdbcType=VARCHAR})</insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.search.HotSearch" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_hot_search <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">id,</if> <if test="orderby != null">`orderby`,</if> <if test="name != null">`name`,</if> </trim>values <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">#{id,jdbcType=BIGINT},</if> <if test="orderby != null">#{orderby,jdbcType=INTEGER},</if> <if test="name != null">#{name,jdbcType=VARCHAR},</if> </trim> </insert> <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.search.HotSearch">update yeshi_ec_hot_search set `orderby` = #{orderby,jdbcType=INTEGER},`name` = #{name,jdbcType=VARCHAR} where id = #{id,jdbcType=BIGINT}</update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.search.HotSearch">update yeshi_ec_hot_search <set> <if test="orderby != null">`orderby`=#{orderby,jdbcType=INTEGER},</if> <if test="name != null">`name`=#{name,jdbcType=VARCHAR},</if> </set> where id = #{id,jdbcType=BIGINT} </update> <select id="listQuery" resultMap="BaseResultMap"> SELECT * FROM (SELECT DISTINCT hc.`id` AS hid FROM yeshi_ec_hot_search hc LEFT JOIN yeshi_ec_super_hot_search sp ON sp.`hotSearch_id` = hc.`id` WHERE 1=1 <if test="systemId != null">AND sp.`system_id` = #{systemId}</if> <if test="key != null and key != ''">AND hc.`name` LIKE '%#{key}%'</if> )A LEFT JOIN yeshi_ec_hot_search h ON A.hid = h.`id` ORDER BY h.`orderby` DESC LIMIT #{start},#{count} </select> <select id="countQuery" resultType="java.lang.Integer"> SELECT IFNULL(COUNT(DISTINCT hc.`id`),0) FROM yeshi_ec_hot_search hc LEFT JOIN yeshi_ec_super_hot_search sp ON sp.`hotSearch_id` = hc.`id` WHERE 1=1 <if test="systemId != null"> AND sp.`system_id` = #{systemId} </if> <if test="key != null and key != ''"> AND hc.`name` LIKE '%#{key}%' </if> </select> </mapper> fanli/src/main/java/com/yeshi/fanli/mapping/goods/SuperHotSearchMapper.xml
New file @@ -0,0 +1,67 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yeshi.fanli.dao.mybatis.goods.SuperHotSearchMapper"> <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.su.search.SuperHotSearch"> <id column="id" property="id" jdbcType="BIGINT"/> <association property="hotSearch" column="hotSearch_id" select="com.yeshi.fanli.dao.mybatis.goods.HotSearchMapper.selectByPrimaryKey"/> <association property="system" column="system_id" javaType="com.yeshi.fanli.entity.system.BusinessSystem"> <id column="system_id" property="id" jdbcType="BIGINT" /> </association> </resultMap> <sql id="Base_Column_List">id,system_id,hotSearch_id</sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select <include refid="Base_Column_List"/>from yeshi_ec_super_hot_search where id = #{id,jdbcType=BIGINT} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_super_hot_search where id = #{id,jdbcType=BIGINT}</delete> <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.su.search.SuperHotSearch" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_super_hot_search (id,system_id,hotSearch_id) values (#{id,jdbcType=BIGINT},#{system.id,jdbcType=BIGINT},#{hotSearch.id,jdbcType=BIGINT})</insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.su.search.SuperHotSearch" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_super_hot_search <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">id,</if> <if test="system != null">system_id,</if> <if test="hotSearch != null">hotSearch_id,</if> </trim>values <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">#{id,jdbcType=BIGINT},</if> <if test="system != null">#{system.id,jdbcType=BIGINT},</if> <if test="hotSearch != null">#{hotSearch.id,jdbcType=BIGINT},</if> </trim> </insert> <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.su.search.SuperHotSearch">update yeshi_ec_super_hot_search set system_id = #{system.id,jdbcType=BIGINT},hotSearch_id = #{hotSearch.id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}</update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.su.search.SuperHotSearch">update yeshi_ec_super_hot_search <set> <if test="system != null">system_id=#{system.id,jdbcType=BIGINT},</if> <if test="hotSearch != null">hotSearch_id=#{hotSearch.id,jdbcType=BIGINT},</if> </set> where id = #{id,jdbcType=BIGINT} </update> <select id="listBySystemId" resultMap="BaseResultMap"> SELECT * FROM yeshi_ec_super_hot_search sp LEFT JOIN yeshi_ec_hot_search hc ON sp.`hotSearch_id` = hc.`id` WHERE sp.`system_id` = #{systemId} ORDER BY hc.`orderby` DESC </select> <select id="listByHotSearchListID" resultMap="BaseResultMap"> SELECT * FROM yeshi_ec_super_hot_search sp WHERE sp.`hotSearch_id` in <foreach collection="list" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> </select> <select id="listBySystemIdAndHotSearchId" resultMap="BaseResultMap"> SELECT * FROM yeshi_ec_super_hot_search sp WHERE sp.`system_id` = #{systemId} AND sp.`hotSearch_id` = #{hid} </select> <delete id="deleteBySystemIdAndHotSearchId"> DELETE FROM yeshi_ec_super_hot_search WHERE system_id = #{systemId} AND hotSearch_id = #{hid} </delete> </mapper> fanli/src/main/java/com/yeshi/fanli/service/impl/config/HotSearchServiceImpl.java
@@ -1,37 +1,26 @@ package com.yeshi.fanli.service.impl.config; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.commons.beanutils.PropertyUtils; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.springframework.orm.hibernate4.HibernateCallback; import org.springframework.stereotype.Service; import com.yeshi.fanli.dao.goods.HotSearchDao; import com.yeshi.fanli.entity.admin.HotSearchAdmin; import com.yeshi.fanli.dao.mybatis.goods.HotSearchMapper; import com.yeshi.fanli.entity.bus.search.HotSearch; import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch; import com.yeshi.fanli.entity.system.BusinessSystem; import com.yeshi.fanli.service.inter.config.BusinessSystemService; import com.yeshi.fanli.service.inter.config.HotSearchService; import com.yeshi.fanli.service.inter.config.SuperHotSearchService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.Utils; @Service public class HotSearchServiceImpl implements HotSearchService { @Resource private HotSearchDao hotSearchDao; private HotSearchMapper hotSearchMapper; @Resource private BusinessSystemService businessSystemService; @@ -39,219 +28,39 @@ @Resource private SuperHotSearchService superHotSearchService; @SuppressWarnings("unchecked") public List<HotSearchAdmin> getHotSearchs(int index, String platform, String packages, String key) { final int strat = index * Constant.PAGE_SIZE; platform = Utils.getMap().get(platform); BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages); List<HotSearch> hotSearchList=null; List<SuperHotSearch> superHotSearchList=null; Map<Long,HotSearchAdmin> hotSearchAdminMap=new HashMap<Long, HotSearchAdmin>(); List<HotSearchAdmin> hotSearchAdmin=new ArrayList<HotSearchAdmin>(); if(system == null){ if("".equals(key.trim())){ hotSearchList = (List<HotSearch>) hotSearchDao.excute(new HibernateCallback<List<HotSearch>>(){ public List<HotSearch> doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(" from HotSearch hs"); query.setFirstResult(strat); query.setMaxResults(Constant.PAGE_SIZE); return query.list(); } }); }else{ final String likekey = "%"+key+"%"; hotSearchList= (List<HotSearch>) hotSearchDao.excute(new HibernateCallback<List<HotSearch>>(){ public List<HotSearch> doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(" from HotSearch hs where hs.name like ? "); query.setFirstResult(strat); query.setMaxResults(Constant.PAGE_SIZE); query.setParameter(0, likekey); return query.list(); } }); } List<Long> hsIdList = new ArrayList<Long>(); for (HotSearch rs : hotSearchList) { hsIdList.add(rs.getId()); } superHotSearchList = superHotSearchService.getSuperHotSearchsByHotSearchs(hsIdList); Map<Long,List<BusinessSystem>> superMap = new HashMap<Long, List<BusinessSystem>>(); Long rsId=null; List<BusinessSystem> systemList=null; for (SuperHotSearch srs : superHotSearchList) { rsId = srs.getHotSearch().getId(); systemList = superMap.get(rsId); if(systemList==null){ systemList=new ArrayList<BusinessSystem>(); } systemList.add(srs.getSystem()); superMap.put(rsId,systemList); } HotSearchAdmin rsa=null; for (HotSearch HotSearch : hotSearchList) { long id = HotSearch.getId(); rsa = hotSearchAdminMap.get(id); if(rsa==null){ rsa=new HotSearchAdmin(); } List<BusinessSystem> list = superMap.get(id); if(list != null){ rsa.getSystemList().addAll(superMap.get(id)); } rsa.setHotSearch(HotSearch); hotSearchAdminMap.put(id, rsa); } }else if(system != null){ if("".equals(key.trim())){ superHotSearchList = superHotSearchService.getSuperHotSearchBySystemId(system.getId(),strat, Constant.PAGE_SIZE); }else{ String likekey = "%"+key+"%"; superHotSearchList = superHotSearchService.getSuperHotSearchBySystemId(system.getId(),strat, Constant.PAGE_SIZE,likekey); } List<Long> hsIdList =new ArrayList<Long>(); for (SuperHotSearch superHotSearch : superHotSearchList) { HotSearch HotSearch = superHotSearch.getHotSearch(); hsIdList.add(HotSearch.getId()); } superHotSearchList = superHotSearchService.getSuperHotSearchsByHotSearchs(hsIdList); HotSearchAdmin rsa=null; for (SuperHotSearch superHotSearch : superHotSearchList) { HotSearch HotSearch = superHotSearch.getHotSearch(); rsa = hotSearchAdminMap.get(HotSearch.getId()); if(rsa==null){ rsa=new HotSearchAdmin(HotSearch); } rsa.getSystemList().add(superHotSearch.getSystem()); hotSearchAdminMap.put(HotSearch.getId(), rsa); } } Map map = Utils.orderBy(hotSearchAdminMap); Collection<HotSearchAdmin> values = map.values(); hotSearchAdmin.addAll(values); return hotSearchAdmin; } public HotSearch getHotSearch(long id) { return hotSearchDao.find(HotSearch.class, id); } public void addHotSearch(HotSearch hotSearch) { hotSearch.setCreatetime(java.lang.System.currentTimeMillis()); hotSearchDao.create(hotSearch); hotSearchMapper.insert(hotSearch); } public Integer deleteHotSearch(final long[] hsids) { return (Integer) hotSearchDao.excute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { session.getTransaction().begin(); try { for (long hsid : hsids) { session.delete(new HotSearch(hsid)); Query query = session.createQuery("delete from SuperHotSearch shs where shs.hotSearch.id = ?"); query.setParameter(0, hsid); query.executeUpdate(); } session.flush(); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); session.getTransaction().rollback(); return 1; } return null; } }); public void deleteHotSearch(long[] hsids) { for (long hsid : hsids) { // superHotSearchService.deleteSuper(id, systemId) hotSearchMapper.deleteByPrimaryKey(hsid); } } public void updateHotSearch(HotSearch hotSearch) { HotSearch updateSearch = new HotSearch(hotSearch.getId()); updateSearch.setName(hotSearch.getName()); updateSearch.setOrderby(hotSearch.getOrderby()); hotSearchDao.update(hotSearch); hotSearchMapper.updateByPrimaryKeySelective(updateSearch); } public int getCount(String platform, String packages, final String key) { platform = Utils.getMap().get(platform); final BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages); return (Integer) hotSearchDao.excute(new HibernateCallback<Integer>() { public Integer doInHibernate(Session session) throws HibernateException { String k = "%"+key+"%"; Query query; if(system==null){ // Query query = session.createSQLQuery("select count(a.name) from (select name from yeshi_ec_hot_search where `name` like ?) a"); query = session.createQuery("select count(hs.id) from HotSearch hs where hs.name like ?"); query.setParameter(0, k); }else{ // Query query =session.createSQLQuery("select count(a.name) from (select hs.name from yeshi_ec_super_hot_search shs left join yeshi_ec_hot_search hs on shs.hotSearch_id=hs.id where shs.system_id=? and hs.name like ?) a"); query = session.createQuery("select count(shs.id) from SuperHotSearch shs where shs.system.id=? and shs.hotSearch.name like ?"); query.setParameter(0, system.getId()); query.setParameter(1, k); } Long result = (Long) query.uniqueResult(); int intValue = result.intValue(); return intValue; } }); } @Override @SuppressWarnings("unchecked") public List<HotSearch> listQuery(int start, int count, String key, Long systemId) throws Exception { List<HotSearch> listObj = null; if (systemId == null) { String hql = "from HotSearch hs where 1=1 "; if (!StringUtil.isNullOrEmpty(key)) { hql += " hs.name like ?"; } final String queryHQL = hql; listObj = (List<HotSearch>) hotSearchDao.excute(new HibernateCallback<List<HotSearch>>() { public List<HotSearch> doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(queryHQL); query.setFirstResult(start); query.setMaxResults(count); if (!StringUtil.isNullOrEmpty(key)) { query.setParameter(0, "%" + key + "%"); } return query.list(); } }); } else { List<SuperHotSearch> superHotSearchList = null; if(StringUtil.isNullOrEmpty(key)){ superHotSearchList = superHotSearchService.getSuperHotSearchBySystemId(systemId,start, count); }else{ String likekey = "%"+key+"%"; superHotSearchList = superHotSearchService.getSuperHotSearchBySystemId(systemId, start, count, likekey); } if (superHotSearchList != null && superHotSearchList.size() > 0) { listObj = new ArrayList<HotSearch>(); for (SuperHotSearch superHotSearch: superHotSearchList) { HotSearch hotSearch = superHotSearch.getHotSearch(); listObj.add(hotSearch); } } } List<HotSearch> listObj = hotSearchMapper.listQuery(start, count, key, systemId); if (listObj == null || listObj.size() == 0) { return null; } List<Long> listId = new ArrayList<>(); for (HotSearch hotSearch : listObj) { listId.add(hotSearch.getId()); @@ -305,29 +114,13 @@ hotSearch.setSystemList(newList); } } return listObj; } @Override public int countList(String key, Long systemId) { return (Integer) hotSearchDao.excute(new HibernateCallback<Integer>() { public Integer doInHibernate(Session session) throws HibernateException { Query query = null; if (StringUtil.isNullOrEmpty(key)) { query = session.createQuery("select count(hs.id) from HotSearch hs"); } else { query = session.createQuery("select count(hs.id) from HotSearch hs where hs.name like ?"); query.setParameter(0, "%"+key+"%"); } Long result = (Long) query.uniqueResult(); return result.intValue(); } }); return hotSearchMapper.countQuery(key, systemId); } } fanli/src/main/java/com/yeshi/fanli/service/impl/config/SuperHotSearchSerivceImpl.java
@@ -1,20 +1,13 @@ package com.yeshi.fanli.service.impl.config; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import org.springframework.cache.annotation.Cacheable; import org.springframework.orm.hibernate4.HibernateCallback; import org.springframework.stereotype.Service; import com.yeshi.fanli.dao.goods.SuperHotSearchDao; import com.yeshi.fanli.dao.mybatis.goods.SuperHotSearchMapper; import com.yeshi.fanli.entity.bus.search.HotSearch; import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch; import com.yeshi.fanli.entity.system.BusinessSystem; @@ -25,131 +18,40 @@ public class SuperHotSearchSerivceImpl implements SuperHotSearchService { @Resource private SuperHotSearchDao superHotSearchDao; private SuperHotSearchMapper superHotSearchMapper; @Resource private BusinessSystemService businessSystemService; public List<SuperHotSearch> getSuperHotSearchBySystemId(long id) { return superHotSearchDao.list("from SuperHotSearch shs where shs.system.id=? order by hotSearch.orderby desc", new Serializable[] { id }); return superHotSearchMapper.listBySystemId(id); } public List<SuperHotSearch> getSuperHotSearchsByHotSearchs(List<Long> hsIdList) { if (hsIdList.size() == 0) { return new ArrayList<SuperHotSearch>(); } StringBuffer sb = new StringBuffer(" from SuperHotSearch shs "); Serializable[] serArr = new Serializable[hsIdList.size()]; for (int i = 0; i < hsIdList.size(); i++) { if (i == 0) { sb.append(" where shs.hotSearch.id=? "); } else { sb.append(" or shs.hotSearch.id=? "); } serArr[i] = hsIdList.get(i); } String hql = sb.toString(); return superHotSearchDao.list(hql, serArr); } public List<SuperHotSearch> getSuperHotSearchBySystemId(long id, int strat, int count) { return superHotSearchDao.list("from SuperHotSearch shs where shs.system.id=?", strat, count, new Serializable[] { id }); } public List<SuperHotSearch> getSuperHotSearchBySystemId(long id, int strat, int count, String key) { return superHotSearchDao.list("from SuperHotSearch srs where srs.system.id=? and srs.hotSearch.name like ?", strat, count, new Serializable[] { id, key }); } @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public List<SuperHotSearch> listSuperHotSearch(List<Long> list) { List<SuperHotSearch> listObj = (List<SuperHotSearch>) superHotSearchDao.excute(new HibernateCallback<List<SuperHotSearch>>() { public List<SuperHotSearch> doInHibernate(Session session) throws HibernateException { Query query = session.createQuery("from SuperHotSearch srs where srs.hotSearch.id in (:array)"); query.setParameterList("array",list); return query.list(); } }); return listObj; if (list == null || list.size() == 0) { return null; } return superHotSearchMapper.listByHotSearchListID(list); } public Integer deleteSuperHotSearch(final long hsid, final String platform, final String packageName) { return (Integer) superHotSearchDao.excute(new HibernateCallback<Integer>() { public Integer doInHibernate(Session session) throws HibernateException { BusinessSystem system = businessSystemService.getBusinessSystem(platform, packageName); Transaction transaction = session.beginTransaction(); Query query = session .createQuery("delete SuperHotSearch shs " + " where shs.hotSearch.id=? and shs.system.id=?"); query.setLong(0, hsid); query.setLong(1, system.getId()); int i = query.executeUpdate(); transaction.commit(); return i; } }); } public void addSuperHotSearch(long hsid, String platform, String packageName) { BusinessSystem system = businessSystemService.getBusinessSystem(platform, packageName); SuperHotSearch superHotSearch = new SuperHotSearch(); HotSearch hotSearch = new HotSearch(); hotSearch.setId(hsid); superHotSearch.setHotSearch(hotSearch); superHotSearch.setSystem(system); superHotSearchDao.create(superHotSearch); } @Cacheable(value = "crgCache", key = "'getSuperHotSearchBySystemIdCache'+#id") @Override @Cacheable(value = "crgCache", key = "'getSuperHotSearchBySystemIdCache'+#id") public List<SuperHotSearch> getSuperHotSearchBySystemIdCache(long id) { return getSuperHotSearchBySystemId(id); } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public List<SuperHotSearch> getHotSearchSystem(Long id, Long systemId) { List<SuperHotSearch> listObj = (List<SuperHotSearch>) superHotSearchDao.excute(new HibernateCallback<List<SuperHotSearch>>() { public List<SuperHotSearch> doInHibernate(Session session) throws HibernateException { Query query = session.createQuery("from SuperHotSearch shs " + " where shs.hotSearch.id=? and shs.system.id=?"); query.setLong(0, id); query.setLong(1,systemId); return query.list(); } }); return listObj; return superHotSearchMapper.listBySystemIdAndHotSearchId(id, systemId); } @Override public Integer deleteSuper(Long id, Long systemId) { return (Integer) superHotSearchDao.excute(new HibernateCallback<Integer>() { public Integer doInHibernate(Session session) throws HibernateException { Transaction transaction = session.beginTransaction(); Query query = session .createQuery("delete SuperHotSearch shs " + " where shs.hotSearch.id=? and shs.system.id=?"); query.setLong(0, id); query.setLong(1, systemId); int i = query.executeUpdate(); transaction.commit(); return i; } }); public void deleteSuper(Long id, Long systemId) { superHotSearchMapper.deleteBySystemIdAndHotSearchId(id,systemId); } @Override @@ -159,6 +61,7 @@ hotSearch.setId(id); superHotSearch.setHotSearch(hotSearch); superHotSearch.setSystem(system); superHotSearchDao.create(superHotSearch); superHotSearchMapper.insert(superHotSearch); } } fanli/src/main/java/com/yeshi/fanli/service/inter/config/HotSearchService.java
@@ -2,22 +2,16 @@ import java.util.List; import com.yeshi.fanli.entity.admin.HotSearchAdmin; import com.yeshi.fanli.entity.bus.search.HotSearch; public interface HotSearchService { List<HotSearchAdmin> getHotSearchs(int index, String platform, String packages, String key); HotSearch getHotSearch(long id); void addHotSearch(HotSearch hotSearch); Integer deleteHotSearch(long[] hsids); void deleteHotSearch(long[] hsids); void updateHotSearch(HotSearch hotSearch); int getCount(String platform, String packages, String key); public List<HotSearch> listQuery(int start, int count, String key, Long systemId) throws Exception; fanli/src/main/java/com/yeshi/fanli/service/inter/config/SuperHotSearchService.java
@@ -12,16 +12,6 @@ public List<SuperHotSearch> getSuperHotSearchBySystemIdCache(long id); public List<SuperHotSearch> getSuperHotSearchsByHotSearchs(List<Long> hsIdList); public List<SuperHotSearch> getSuperHotSearchBySystemId(long id, int strat, int count); public List<SuperHotSearch> getSuperHotSearchBySystemId(long id, int strat, int count, String likekey); public Integer deleteSuperHotSearch(long hsid, String platform, String packageName); public void addSuperHotSearch(long hsid, String platform, String packageName); public List<SuperHotSearch> listSuperHotSearch(List<Long> list); @@ -40,7 +30,7 @@ * @param systemId * @return */ public Integer deleteSuper(Long id, Long systemId); public void deleteSuper(Long id, Long systemId); /** * 新增系统