pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/controller/admin/api/ClassController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/controller/admin/api/HomeTypeController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/env-dev/solr.properties | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/solr.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/webapp/admin/new/fenqu.html | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/webapp/admin/new/tuijian-lanmuneirong-videos.html | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/test/java/com/hxh/spring/test/SolrTest.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
pom.xml
@@ -527,21 +527,24 @@ <artifactId>ikanalyzer</artifactId> <version>2012_u6</version> </dependency> <!--spring data solr--> <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-solr --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-solr</artifactId> <version>1.5.6.RELEASE</version> <version>4.3.5</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.solr/solr-solrj --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-solr</artifactId> <version>1.5.6.RELEASE</version> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>8.7.0</version> </dependency> <dependency> <groupId>com.xuxueli</groupId> <artifactId>xxl-job-core</artifactId> src/main/java/com/yeshi/buwan/controller/admin/api/ClassController.java
@@ -96,8 +96,8 @@ } @RequestMapping(value = "/gethometypelist", method = RequestMethod.POST) public void getHomeTypeList(int pid, PrintWriter out) { List<HomeType> list = homeTypeService.getHomeType(); public void getHomeTypeList(int pid, HttpSession session, PrintWriter out) { List<HomeType> list = homeTypeService.getHomeTypeList(SystemUtil.getAdminSelectedSystemId(session)); JSONArray array = new JSONArray(); if (list != null) src/main/java/com/yeshi/buwan/controller/admin/api/HomeTypeController.java
@@ -40,14 +40,16 @@ private HomeTypeService homeTypeService; @RequestMapping(value = "/gethometypelist", method = RequestMethod.POST) public void getHomeTypeList(PrintWriter out) { List<HomeType> list = homeTypeService.getHomeType(); public void getHomeTypeList(HttpSession session, PrintWriter out) { List<HomeType> list = homeTypeService.getHomeTypeList(SystemUtil.getAdminSelectedSystemId(session)); JSONArray array = new JSONArray(); Gson gson = new GsonBuilder().create(); for (HomeType ht : list) { ht.setHomeVideoList(null); ht.setItemTypeList(null); ht.setVideoList(null); ht.setAdmin(null); ht.setSystem(null); array.add(gson.toJson(ht)); } JSONObject object = new JSONObject(); @@ -239,6 +241,10 @@ public void getHomeVideoList(long id, int page, String key, PrintWriter out) { key = StringUtil.isNullOrEmpty(key) ? "" : key; List<HomeVideo> list = homeTypeService.getHomeVideoList(id + "", key, page); for(HomeVideo homeVideo:list){ homeVideo.setType(null); homeVideo.setAdmin(null); } long count = homeTypeService.getHomeVideoListCount(id + "", key); PageEntity pe = new PageEntity(); pe.setPageIndex(page); src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java
@@ -35,10 +35,15 @@ @Resource private VideoResourceMapExtraInfoService videoResourceMapExtraInfoService; public List<HomeType> getHomeType() { public List<HomeType> getHomeTypeDetailList() { List<HomeType> list = homeTypeDao.list("from HomeType h order by h.orderby desc"); return getHomeType(list); } public List<HomeType> getHomeTypeList(String systemId){ List<HomeType> list = homeTypeDao.list("from HomeType h where h.system.id=? order by h.orderby desc",systemId); return list; } @SuppressWarnings("unchecked") @@ -231,7 +236,7 @@ for (HomeVideo sp : homeVideoList) session.delete(sp); session.delete(new HomeType(id)); session.delete(session.get(HomeType.class,id)); session.flush(); session.getTransaction().commit(); } catch (Exception e) { @@ -341,7 +346,7 @@ for (int i = 0; i < list.size(); i++) { List<HomeVideo> videoList = session .createQuery( "select h from HomeVideo h LEFT JOIN h.juhe as v where v.id=h.video.id and h.video.show='1' and hometype=:hometype order by v.orderby desc,v.watchCount desc,h.createtime desc") "select h from HomeVideo h where h.video.show='1' and hometype=:hometype order by h.video.orderby desc,h.video.watchCount desc,h.video.createtime desc") .setParameter("hometype", ((HomeType) list.get(i)).getId()).setFirstResult(0) .setMaxResults(list.get(i).getNumber()).list(); ((HomeType) list.get(i)).setHomeVideoList(videoList); src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java
@@ -12,27 +12,27 @@ import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService; import com.yeshi.buwan.util.StringUtil; import com.yeshi.buwan.util.factory.SolrVideoFactory; import net.sf.ehcache.search.expression.BaseCriteria; import org.apache.solr.client.solrj.response.UpdateResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.Sort; import org.springframework.data.solr.core.SolrTemplate; import org.springframework.data.solr.core.query.*; import org.springframework.data.solr.core.query.Criteria; import org.springframework.data.solr.core.query.Query; import org.springframework.data.solr.core.query.SimpleQuery; import org.springframework.data.solr.core.query.result.ScoredPage; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.*; /** * 搜索引擎-专辑数据管理 */ @Component public class SolrAlbumDataManager { private final static String CORE_NAME = "buwan_album"; private final Logger logger = LoggerFactory.getLogger(SolrAlbumDataManager.class); @@ -50,11 +50,11 @@ public void saveOrUpdate(VideoInfo videoInfo) { UpdateResponse updateResponse = solrTemplate.saveBean(SolrVideoFactory.create(videoInfo, videoInfo.getResourceList())); UpdateResponse updateResponse = solrTemplate.saveBean(CORE_NAME, SolrVideoFactory.create(videoInfo, videoInfo.getResourceList())); if (updateResponse.getStatus() == 0) { solrTemplate.commit(); solrTemplate.commit(CORE_NAME); } else { solrTemplate.rollback(); solrTemplate.rollback(CORE_NAME); } } @@ -63,11 +63,11 @@ for (VideoInfo vi : videoInfoList) { solrVideoList.add(SolrVideoFactory.create(vi, vi.getResourceList())); } UpdateResponse updateResponse = solrTemplate.saveBeans(solrVideoList); UpdateResponse updateResponse = solrTemplate.saveBeans(CORE_NAME, solrVideoList); if (updateResponse.getStatus() == 0) { solrTemplate.commit(); solrTemplate.commit(CORE_NAME); } else { solrTemplate.rollback(); solrTemplate.rollback(CORE_NAME); } } @@ -84,17 +84,17 @@ // } // } public void deleteById(String id) { UpdateResponse updateResponse = solrTemplate.deleteById(id); UpdateResponse updateResponse = solrTemplate.deleteByIds(CORE_NAME, id); if (updateResponse.getStatus() == 0) { solrTemplate.commit(); solrTemplate.commit(CORE_NAME); } else { solrTemplate.rollback(); solrTemplate.rollback(CORE_NAME); } } public SolrVideo findOne(String id) { SolrVideo solrVideo = solrTemplate.getById(id, SolrVideo.class); return solrVideo; Optional<SolrVideo> solrVideo = solrTemplate.getById(CORE_NAME, id, SolrVideo.class); return solrVideo.get(); } public SolrResultDTO find(SolrVideoSearchFilter filter, int page, int pageSize) { @@ -133,7 +133,7 @@ query.addCriteria(criteria); /** 设置分页开始记录数(第一页) 默认0 */ query.setOffset((page - 1) * pageSize); query.setOffset((page - 1) * pageSize * 1L); /** 设置每页显示记录数,默认10 */ query.setRows(pageSize); if (StringUtil.isNullOrEmpty(filter.getSortKey())) { @@ -141,7 +141,7 @@ } else { query.addSort(new Sort(Sort.Direction.DESC, filter.getSortKey())); } ScoredPage<SolrVideo> result = solrTemplate.queryForPage(query, SolrVideo.class); ScoredPage<SolrVideo> result = solrTemplate.queryForPage(CORE_NAME, query, SolrVideo.class); System.out.println("总记录数:" + result.getTotalElements()); List<SolrVideo> list = result.getContent(); return new SolrResultDTO(list, (int) result.getTotalElements()); @@ -150,10 +150,10 @@ public List<String> getSuggestKeyList(String key) { Query query = new SimpleQuery("name:\"" + key + "\""); /** 设置分页开始记录数(第一页) 默认0 */ query.setOffset(0); query.setOffset(0L); /** 设置每页显示记录数,默认10 */ query.setRows(10); ScoredPage<SolrVideo> result = solrTemplate.queryForPage(query, SolrVideo.class); ScoredPage<SolrVideo> result = solrTemplate.queryForPage(CORE_NAME, query, SolrVideo.class); System.out.println("总记录数:" + result.getTotalElements()); List<SolrVideo> list = result.getContent(); List<String> keyList = new ArrayList<>(); src/main/resources/env-dev/solr.properties
@@ -1 +1,3 @@ solr.url=http://203.195.196.115:8983/solr/buwan_album solr.url=http://203.195.196.115:8983/solr solr.user=solr solr.pwd=IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c= src/main/resources/solr.xml
@@ -2,15 +2,20 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:solr="http://www.springframework.org/schema/data/solr" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation="http://www.springframework.org/schema/data/solr http://www.springframework.org/schema/data/solr/spring-solr.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd"> <solr:solr-server id="solrServer" url="${solr.url}"/> <solr:solr-client id="solrClient" url="${solr.url}" /> <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate"> <constructor-arg name="solrServer" ref="solrServer"/> <constructor-arg ref="solrServer"/> </bean> </beans> src/main/webapp/admin/new/fenqu.html
@@ -319,19 +319,15 @@ <th>栏目ID</th> <th>栏目名称</th> <th>选择</th> <th>栏目ID</th> <th>栏目名称</th> <th>选择</th> </thead> <tbody> <tr> <td>12</td> <td>热门推荐</td> <td><input type="checkbox"/></td> </tr> <tr> <td>12</td> <td>热门推荐</td> <td><input type="checkbox"/></td> </tr> <tr> <td>12</td> <td>热门推荐</td> <td><input type="checkbox"/></td> @@ -376,16 +372,6 @@ <th>选择</th> </thead> <tbody> <tr> <td>12</td> <td>热门推荐</td> <td><input type="checkbox"/></td> </tr> <tr> <td>12</td> <td>热门推荐</td> <td><input type="checkbox"/></td> </tr> <tr> <td>12</td> <td>热门推荐</td> @@ -522,13 +508,86 @@ if (data.code == 0) { var item = $("#hometype table tbody tr").eq(0); $("#hometype table tbody").empty(); data.data.forEach(function (hometype) { var homeTypeList = data.data; var rows = homeTypeList.length % 2 == 0 ? homeTypeList.length / 2 : parseInt(homeTypeList.length / 2) + 1; for (var i = 0; i < rows; i++) { $("#hometype table tbody").append("<tr>" + item.html() + "</tr>"); var newItem = $("#hometype table tbody tr").eq($("#hometype table tbody tr").length - 1); newItem.find("td").eq(0).html(hometype.id); newItem.find("td").eq(1).html(hometype.name); newItem.find("td").eq(2).find("input[type='checkbox']").eq(0).val(hometype.id); newItem.find("td").eq(0).html(homeTypeList[i * 2].id); newItem.find("td").eq(1).html(homeTypeList[i * 2].name); newItem.find("td").eq(2).find("input[type='checkbox']").eq(0).val(homeTypeList[i * 2].id); if (homeTypeList.length > i * 2 + 1) { newItem.find("td").eq(3).html(homeTypeList[i * 2 + 1].id); newItem.find("td").eq(4).html(homeTypeList[i * 2 + 1].name); newItem.find("td").eq(5).find("input[type='checkbox']").eq(0).val(homeTypeList[i * 2 + 1].id); } else { newItem.find("td").eq(3).empty(); newItem.find("td").eq(4).empty(); newItem.find("td").eq(5).empty(); } newItem.css("cursor", "pointer"); //设置颜色 if (i % 2 == 0) { newItem.find("td").css("background", "#EEEEEE"); } newItem.find("td").click(function () { //查询当前tr的本个/下一个checkbox console.log($(this).find("input[type='checkbox']")); if ($(this).find("input[type='checkbox']").length > 0) { if ($(this).find("input[type='checkbox']").is(":checked")) { //取消选中 $(this).find("input[type='checkbox']").prop('checked', false); } else { //选中 $(this).find("input[type='checkbox']").prop('checked', true); } } else { //查询下一个 var $this = $(this); for (var i = 0; i < 3; i++) { var checkb = $this.next().find("input[type='checkbox']"); if (checkb.length > 0) { if (checkb.is(":checked")) { //取消选中 checkb.prop('checked', false); } else { //选中 checkb.prop('checked', true); } break; } else { $this = $this.next(); } } } return false; }); newItem.find("input[type='checkbox']").bind("click", function (event) { var $this = $(this); var checked = $this.is(":checked"); console.log('checkbox:' + checked) setTimeout(function () { if (checked) { //选中 $this.prop('checked', true); console.log("设置选中") } else { //取消选中 $this.prop('checked', false); console.log("取消选中") } }); return false; }); } } }, 'json'); @@ -544,6 +603,7 @@ newItem.find("td").eq(0).html(special.id); newItem.find("td").eq(1).html(special.name); newItem.find("td").eq(2).find("input[type='checkbox']").eq(0).val(special.id); }); } }, 'json'); @@ -629,23 +689,29 @@ } $(".table .addrecommend a").bind("click", function () { var index = layer.open({ type: 1, skin: 'layui-layer-demo', //样式类名 closeBtn: 0, //不显示关闭按钮 anim: 2, area: ['500px', '250px'], shadeClose: true, //开启遮罩关闭 content: $("#hometype-sure") }); //直接添加到推荐 var key = $(this).attr("key"); $("#hometype-sure input[type=button]").click(function () { $("#hometype .picture").val($("#hometype-sure .picture").val()); $("#hometype .desc").val($("#hometype-sure .desc").val()); $("#hometype .videoids").val(key); layer.close(index); $("#hometype").modal("show"); }); // var index = layer.open({ // type: 1, // skin: 'layui-layer-demo', //样式类名 // closeBtn: 0, //不显示关闭按钮 // anim: 2, // area: ['500px', '250px'], // shadeClose: true, //开启遮罩关闭 // content: $("#hometype-sure") // }); // var key = $(this).attr("key"); // $("#hometype-sure input[type=button]").click(function () { // $("#hometype .picture").val($("#hometype-sure .picture").val()); // $("#hometype .desc").val($("#hometype-sure .desc").val()); // $("#hometype .videoids").val(key); // layer.close(index); // $("#hometype").modal("show"); // }); }); @@ -718,9 +784,9 @@ $("#hometype .modal-footer button:last").click(function () { var ids = ""; for (var i = 0; i < $("#hometype .table tr").length; i++) { if ($("#hometype .table tr td input[type=checkbox]").eq(i).is(':checked')) { ids += $("#hometype .table tr td input[type=checkbox]").eq(i).val() + ","; for (var i = 0; i < $("#hometype .table td").length; i++) { if ($("#hometype .table td input[type=checkbox]").eq(i).is(':checked')) { ids += $("#hometype .table td input[type=checkbox]").eq(i).val() + ","; } } if (ids.length < 1) { @@ -730,7 +796,6 @@ if (ids.length > 0) ids = ids.substr(0, ids.length - 1); alert(ids); $.post('api/home/addhomevideos', { 'videoids': $("#hometype .videoids").val(), src/main/webapp/admin/new/tuijian-lanmuneirong-videos.html
@@ -214,7 +214,7 @@ fk.find(".check-item").attr("key", da.id); fk.find(".homevideoid").html(da.id); fk.find(".name").html(da.video.name); var pic = da.picture==null ? da.video.picture:da.picture; var pic = (da.picture==null||da.picture.length==0) ? da.video.hpicture:da.picture; fk.find(".picture img").attr("src", pic); //fk.find(".picture img").attr("src", (da.picture.length < 8 ? da.juhe.hpicture : da.picture)); fk.find(".tag").html(da.tag); src/test/java/com/hxh/spring/test/SolrTest.java
@@ -11,6 +11,8 @@ import com.yeshi.buwan.service.manager.SolrAlbumDataManager; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.solr.server.support.HttpSolrClientFactory; import org.springframework.data.solr.server.support.HttpSolrClientFactoryBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; @@ -48,6 +50,9 @@ @Test public void addSolrAlbum() { solrDataManager.syncAlbum("8224447"); HttpSolrClientFactory factory=new HttpSolrClientFactory(); }