Merge branch 'bkoff-develop' into 'master'

新增样本批量删除

See merge request !10
This commit is contained in:
2021-04-12 16:32:19 +08:00
10 changed files with 122 additions and 17 deletions
+2 -2
View File
@@ -29,7 +29,7 @@
<dependency>
<groupId>org.sothis</groupId>
<artifactId>sothis-core</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -154,7 +154,7 @@
<dependency>
<groupId>com.poseidon</groupId>
<artifactId>poseidon-message</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>
+1 -1
View File
@@ -99,7 +99,7 @@
<dependency>
<groupId>org.sothis</groupId>
<artifactId>sothis-web</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@@ -12,6 +12,7 @@ import com.fangjia.service.mongo.fangjia.SeawaterService;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.sothis.core.util.Pager;
import org.sothis.web.mvc.annotation.Param;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
@@ -116,6 +117,14 @@ public class SeawaterController {
return ret;
}
public Object batchDeleteAction(@Param(name="ids") String ids) throws UnsupportedEncodingException {
JsonModel ret = new JsonModel();
if (StringUtils.isNotBlank(ids)){
seawaterService.deleteByIds(ids);
}
return ret;
}
public void setSeawaterService(SeawaterService seawaterService) {
this.seawaterService = seawaterService;
}
@@ -118,9 +118,13 @@
</td>
</tr>
</table>
<span style="font-size:12px;">查询到<b style="color:red;">${pager.totalRows!}</b>条记录</span>
<div>
<span style="font-size:12px;">查询到<b style="color:red;">${pager.totalRows!}</b>条记录</span>
<input class ="btn btn-primary" id="batchDelete" type="submit" value="批量删除" style="float: right" />
</div>
<table id="dataSheet" class="table table-hover table-condensed" name="reginTable">
<tr>
<th style="width:30px;"><input type="checkbox" id="checkAll"/>全选</th>
<th style="width:60px;">类型</th>
<th style="width:50px;">区域</th>
<th style="width:130px;">小区名</th>
@@ -142,6 +146,7 @@
<#if seawaterList??>
<#list seawaterList as it>
<tr>
<td><input type="checkbox" name="houseCheck" value="${it.id}"/></td>
<td>
<#if it.category! == 'sell'>
二手房
@@ -249,7 +254,7 @@
}
});
}
changeCity('${cityDisplay!}');
$(".hrefClick").click(function(){
@@ -336,8 +341,48 @@
$("#roomSpan").hide();
}
}
// 全选
$("#checkAll").click(function(){
$('input[name="houseCheck"]').each(function() {
var _this = this
if (_this.checked == true) {
_this.checked = false
} else {
_this.checked = true
}
})
})
$("#batchDelete").click(function(){
if(confirm('确认要删除所选的数据吗?')) {
var ids = "";
$('input:checkbox[name=houseCheck]:checked').each(function() {
var _this = $(this);
ids += _this.val() + ","
});
if (ids == "") {
alert("请选择数据")
return false;
}
jQuery.ajax({
type: 'POST',
url: '../seawater/batchDelete',
data:{ids:ids},
dataType: 'json',
timeout: 100000,
success: function(model) {
alert("批量删除操作成功");
location.reload();
},
error : function() {
//alert("操作失败");
}
});
}
});
</script>
</html>
</#compress>
@@ -205,7 +205,6 @@ public abstract class ElasticDaoImpl<E extends MongoEntity> extends AbstractJpaC
@Override
public void deleteByIds(List<String> idList) {
}
@Override
@@ -14,10 +14,8 @@ public interface SeawaterDao extends com.fangjia.dal.SeawaterDao<Seawater> {
Seawater findByIdFromEs(String id,String table);
List<Seawater> findSeawatersFromEs(String category, String city, String region, String name, List<String> alias, List<String> regionAlias, Integer startDate, Integer endDate,
Double startArea, Double endArea, Integer startPrice, Integer endPrice, Integer room, String root, String sort, boolean order, int start, int limit , String table);
List<Seawater> findHouses(String city, String region, List<String> alias, Integer minPrice, Integer maxPrice, Integer limit);
}
@@ -96,6 +96,44 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
return new ArrayList<Seawater>();
}
@Override
public void deleteById(String id) {
deleteByIds(Arrays.asList(id));
}
private Map<String, String> buildHeader() {
Base64 token = new Base64();
String authenticationEncoding = token.encodeAsString(new String("" + ES_USER + ":" + ES_PASSWORD + "").getBytes());
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Basic " + authenticationEncoding + "");
return headers;
}
@Override
public void deleteByIds(List<String> idList) {
HttpRequest request = new HttpRequest();
JSONObject reqBody = new JSONObject();
JSONObject query = new JSONObject();
JSONObject bool = new JSONObject();
JSONArray must = new JSONArray();
must.add(addTerms("_id", idList));
bool.put("must", must);
query.put("bool", bool);
reqBody.put("query", query);
JSONObject script = new JSONObject();
script.put("source", "ctx._source.status=1");
reqBody.put("script", script);
try {
request.postWithBody("http://es.fangjia.com:9200/seawater/_update_by_query", reqBody, this.buildHeader(), "UTF-8");
} catch (HttpRequestException e) {
e.printStackTrace();
}
}
private JSONObject addMatch(String name, String value){
JSONObject term = new JSONObject();
JSONObject match = new JSONObject();
@@ -338,6 +376,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
if(limit >= 0){
reqBody.put("size", limit);
}
// ²»Õ¹Ê¾É¾³ý
JSONObject param = new JSONObject();
param.put("status", 0);
JSONObject temp = new JSONObject();
temp.put("term", param);
jsonList.add(temp);
query.put("must", jsonList);
q.put("bool", query);
reqBody.put("query", q);
@@ -31,10 +31,15 @@ public interface SeawaterService {
void deleteById(String id);
/**
* 批量删除,英文逗号分割,如1,2,3
* @param ids
*/
void deleteByIds(String ids);
@Deprecated
List<Seawater> findAllSeawater(String category, String city, String name, String region, Integer room, String root, String sort, Integer startDate, Integer endDate, int start, int limit, boolean order, String[] fields);
@Deprecated
int findAllSeawaterCount(String category, String city, String name, String region, Integer room, String root, Integer startDate, Integer endDate);
}
@@ -12,10 +12,7 @@ import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.solr.client.solrj.util.ClientUtils;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
public class SeawaterServiceImpl implements SeawaterService {
private SeawaterDao seawaterDao;
@@ -188,6 +185,12 @@ public class SeawaterServiceImpl implements SeawaterService {
seawaterDao.deleteById(id);
}
@Override
public void deleteByIds(String ids) {
String[] idArr = ids.split(",");
seawaterDao.deleteByIds(Arrays.asList(idArr));
}
public void setSeawaterDao(SeawaterDao seawaterDao) {
this.seawaterDao = seawaterDao;
}
+2 -2
View File
@@ -29,7 +29,7 @@
<dependency>
<groupId>org.sothis</groupId>
<artifactId>sothis-core</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -154,7 +154,7 @@
<dependency>
<groupId>com.poseidon</groupId>
<artifactId>poseidon-message</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>