|
@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.szwl.feign.SzwlFeign;
|
|
import com.szwl.feign.SzwlFeign;
|
|
import com.szwl.model.bean.ChartBean;
|
|
import com.szwl.model.bean.ChartBean;
|
|
import com.szwl.model.bean.ChartColumn;
|
|
import com.szwl.model.bean.ChartColumn;
|
|
|
|
+import com.szwl.model.bean.SellChartBean;
|
|
|
|
+import com.szwl.model.bean.SellChartColumn;
|
|
import com.szwl.model.bo.R;
|
|
import com.szwl.model.bo.R;
|
|
import com.szwl.model.bo.ResponseModel;
|
|
import com.szwl.model.bo.ResponseModel;
|
|
import com.szwl.model.entity.TEquipment;
|
|
import com.szwl.model.entity.TEquipment;
|
|
@@ -57,6 +59,7 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
EsTOrderService esTOrderService;
|
|
EsTOrderService esTOrderService;
|
|
@Autowired
|
|
@Autowired
|
|
SzwlFeign szwlFeign;
|
|
SzwlFeign szwlFeign;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public String getTableName() {
|
|
public String getTableName() {
|
|
return "es_t_equipment";
|
|
return "es_t_equipment";
|
|
@@ -79,21 +82,21 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void initTableFun() {
|
|
public void initTableFun() {
|
|
- try{
|
|
|
|
|
|
+ try {
|
|
String tableName = getTableName();
|
|
String tableName = getTableName();
|
|
GetIndexRequest request = new GetIndexRequest(tableName);
|
|
GetIndexRequest request = new GetIndexRequest(tableName);
|
|
// DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(this.getTableName());
|
|
// DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(this.getTableName());
|
|
// restHighLevelClient.indices().delete(deleteIndexRequest,RequestOptions.DEFAULT);
|
|
// restHighLevelClient.indices().delete(deleteIndexRequest,RequestOptions.DEFAULT);
|
|
boolean isExists = restHighLevelClient.indices().exists(request, RequestOptions.DEFAULT);
|
|
boolean isExists = restHighLevelClient.indices().exists(request, RequestOptions.DEFAULT);
|
|
if (!isExists) {
|
|
if (!isExists) {
|
|
- log.info("es 索引 开始创建"+tableName);
|
|
|
|
|
|
+ log.info("es 索引 开始创建" + tableName);
|
|
createTable();
|
|
createTable();
|
|
// 初始化旧流水
|
|
// 初始化旧流水
|
|
int num = 0;
|
|
int num = 0;
|
|
while (true) {
|
|
while (true) {
|
|
int limit = MAX_ROW;
|
|
int limit = MAX_ROW;
|
|
// int offset= num * MAX_ROW;
|
|
// int offset= num * MAX_ROW;
|
|
- int offset= num;
|
|
|
|
|
|
+ int offset = num;
|
|
|
|
|
|
LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
|
|
Page<TEquipment> page = new Page<>(offset, limit, true);
|
|
Page<TEquipment> page = new Page<>(offset, limit, true);
|
|
@@ -105,16 +108,16 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
// List<TEquipment> list = tEquipmentService.selectByOption(example);
|
|
// List<TEquipment> list = tEquipmentService.selectByOption(example);
|
|
insertBatch(list);
|
|
insertBatch(list);
|
|
num++;
|
|
num++;
|
|
- if(list.size()< MAX_ROW){ // 数据小于 最大值 ,证明后面已无数据,则跳出
|
|
|
|
|
|
+ if (list.size() < MAX_ROW) { // 数据小于 最大值 ,证明后面已无数据,则跳出
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- log.info("es 索引 "+tableName+" 已存在不再创建");
|
|
|
|
|
|
+ log.info("es 索引 " + tableName + " 已存在不再创建");
|
|
}
|
|
}
|
|
InitEsTableStatus = true;
|
|
InitEsTableStatus = true;
|
|
- }catch (Exception e){
|
|
|
|
- log.error("ElasticsearchRunner InitEsTEquipmentThread 发生错误:{}" , e);
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("ElasticsearchRunner InitEsTEquipmentThread 发生错误:{}", e);
|
|
throw new MyException("ElasticsearchRunner InitEsTEquipmentThread 发生错误:" + e.getMessage());
|
|
throw new MyException("ElasticsearchRunner InitEsTEquipmentThread 发生错误:" + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -133,8 +136,10 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
// public TEquipment setEntityPrimaryKey(TEquipment tEquipment, String value) {
|
|
// public TEquipment setEntityPrimaryKey(TEquipment tEquipment, String value) {
|
|
// return tEquipment.setId(Long.parseLong(value));
|
|
// return tEquipment.setId(Long.parseLong(value));
|
|
// }
|
|
// }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据时间 重新同步es
|
|
* 根据时间 重新同步es
|
|
|
|
+ *
|
|
* @param
|
|
* @param
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@@ -172,40 +177,41 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
|
|
|
|
|
|
|
|
public ChartColumn getEquipmentStatistics(StatisticsParam param) {
|
|
public ChartColumn getEquipmentStatistics(StatisticsParam param) {
|
|
- if(StringUtils.equals("0",param.getIfForeign())) { // 国内用户
|
|
|
|
|
|
+ if (StringUtils.equals("0", param.getIfForeign())) { // 国内用户
|
|
return getEquipmentStatistics_0(param);
|
|
return getEquipmentStatistics_0(param);
|
|
- }else{ // 国外用户
|
|
|
|
|
|
+ } else { // 国外用户
|
|
return getEquipmentStatistics_1(param);
|
|
return getEquipmentStatistics_1(param);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 统计 国内
|
|
* 统计 国内
|
|
|
|
+ *
|
|
* @param param
|
|
* @param param
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public ChartColumn getEquipmentStatistics_0(StatisticsParam param) {
|
|
public ChartColumn getEquipmentStatistics_0(StatisticsParam param) {
|
|
BoolQueryBuilder boolQueryBuilder;
|
|
BoolQueryBuilder boolQueryBuilder;
|
|
- String startDate = param.getStartDate().replace("/","-");
|
|
|
|
- String endDate = param.getEndDate().replace("/","-");
|
|
|
|
- Date start = DateUtils.parseDate(startDate+" 00:00:00",DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss,new Date());
|
|
|
|
- Date end = DateUtils.parseDate(endDate+" 23:59:59",DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss,new Date());
|
|
|
|
|
|
+ String startDate = param.getStartDate().replace("/", "-");
|
|
|
|
+ String endDate = param.getEndDate().replace("/", "-");
|
|
|
|
+ Date start = DateUtils.parseDate(startDate + " 00:00:00", DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss, new Date());
|
|
|
|
+ Date end = DateUtils.parseDate(endDate + " 23:59:59", DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss, new Date());
|
|
TOrderParam tOrderParam = new TOrderParam();
|
|
TOrderParam tOrderParam = new TOrderParam();
|
|
tOrderParam.setStatus(1);
|
|
tOrderParam.setStatus(1);
|
|
- if(param.getEquipmentIds()!=null&¶m.getEquipmentIds().size()>0){ // 设备id
|
|
|
|
|
|
+ if (param.getEquipmentIds() != null && param.getEquipmentIds().size() > 0) { // 设备id
|
|
tOrderParam.setEquipmentId_inList(param.getEquipmentIds());
|
|
tOrderParam.setEquipmentId_inList(param.getEquipmentIds());
|
|
}
|
|
}
|
|
tOrderParam.setCreateDate_start(start);
|
|
tOrderParam.setCreateDate_start(start);
|
|
tOrderParam.setCreateDate_end(end);
|
|
tOrderParam.setCreateDate_end(end);
|
|
- if(StringUtils.isNotEmpty(param.getAdminId())){ // 所属商家id
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(param.getAdminId())) { // 所属商家id
|
|
tOrderParam.setAdminId(Long.parseLong(param.getAdminId()));
|
|
tOrderParam.setAdminId(Long.parseLong(param.getAdminId()));
|
|
}
|
|
}
|
|
|
|
|
|
boolQueryBuilder = esTOrderService.getParam2QueryBuilder(tOrderParam);
|
|
boolQueryBuilder = esTOrderService.getParam2QueryBuilder(tOrderParam);
|
|
// 公司平台
|
|
// 公司平台
|
|
String companyType = param.getCompanyType();
|
|
String companyType = param.getCompanyType();
|
|
- if(StringUtils.isNotEmpty(companyType)) {
|
|
|
|
- if(companyType.equals("0")) {
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(companyType)) {
|
|
|
|
+ if (companyType.equals("0")) {
|
|
boolQueryBuilder.must(
|
|
boolQueryBuilder.must(
|
|
QueryBuilders.boolQuery().should(
|
|
QueryBuilders.boolQuery().should(
|
|
QueryBuilders.termQuery("companyType", "0")
|
|
QueryBuilders.termQuery("companyType", "0")
|
|
@@ -216,13 +222,13 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
)
|
|
)
|
|
);
|
|
);
|
|
} else {
|
|
} else {
|
|
- boolQueryBuilder.must(QueryBuilders.termQuery("companyType","1"));
|
|
|
|
|
|
+ boolQueryBuilder.must(QueryBuilders.termQuery("companyType", "1"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 设备类型
|
|
// 设备类型
|
|
String machineType = param.getMachineType();
|
|
String machineType = param.getMachineType();
|
|
- if(StringUtils.isNotEmpty(machineType)) {
|
|
|
|
- if(machineType.equals("0")) {
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(machineType)) {
|
|
|
|
+ if (machineType.equals("0")) {
|
|
boolQueryBuilder.must(
|
|
boolQueryBuilder.must(
|
|
QueryBuilders.boolQuery().should(
|
|
QueryBuilders.boolQuery().should(
|
|
QueryBuilders.termQuery("machineType", "0")
|
|
QueryBuilders.termQuery("machineType", "0")
|
|
@@ -233,15 +239,15 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
)
|
|
)
|
|
);
|
|
);
|
|
} else {
|
|
} else {
|
|
- boolQueryBuilder.must(QueryBuilders.termQuery("machineType",machineType));
|
|
|
|
|
|
+ boolQueryBuilder.must(QueryBuilders.termQuery("machineType", machineType));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if("1".equals(param.getChangeType())){
|
|
|
|
|
|
+ if ("1".equals(param.getChangeType())) {
|
|
// 花型统计
|
|
// 花型统计
|
|
- return getEquipmentStatistics(boolQueryBuilder,esTOrderService.getTableName(),"productName.keyword");
|
|
|
|
- }else{
|
|
|
|
|
|
+ return getEquipmentStatistics(boolQueryBuilder, esTOrderService.getTableName(), "productName.keyword");
|
|
|
|
+ } else {
|
|
log.info("1");
|
|
log.info("1");
|
|
- ChartColumn chartColumn = getEquipmentStatistics(boolQueryBuilder,esTOrderService.getTableName(),"equipmentId");
|
|
|
|
|
|
+ ChartColumn chartColumn = getEquipmentStatistics(boolQueryBuilder, esTOrderService.getTableName(), "equipmentId");
|
|
|
|
|
|
// 设置categories
|
|
// 设置categories
|
|
ArrayList<String> equipmentIdList = chartColumn.getCategories();
|
|
ArrayList<String> equipmentIdList = chartColumn.getCategories();
|
|
@@ -249,15 +255,15 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
// for(String e:equipmentIdList){
|
|
// for(String e:equipmentIdList){
|
|
// list.add(Long.valueOf(e));
|
|
// list.add(Long.valueOf(e));
|
|
// }
|
|
// }
|
|
- for(String e:equipmentIdList){
|
|
|
|
|
|
+ for (String e : equipmentIdList) {
|
|
TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(e));
|
|
TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(e));
|
|
- if(equipment!=null&&equipment.getId()!=null){
|
|
|
|
- if(StringUtils.isNotEmpty(equipment.getName())){
|
|
|
|
|
|
+ if (equipment != null && equipment.getId() != null) {
|
|
|
|
+ if (StringUtils.isNotEmpty(equipment.getName())) {
|
|
list.add(equipment.getName());
|
|
list.add(equipment.getName());
|
|
- }else {
|
|
|
|
- list.add(equipment.getClientId().substring(equipment.getClientId().length()-6,equipment.getClientId().length()));
|
|
|
|
|
|
+ } else {
|
|
|
|
+ list.add(equipment.getClientId().substring(equipment.getClientId().length() - 6, equipment.getClientId().length()));
|
|
}
|
|
}
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
list.add(e);
|
|
list.add(e);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -297,65 +303,53 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
return chartColumn;
|
|
return chartColumn;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 统计 国外
|
|
* 统计 国外
|
|
|
|
+ *
|
|
* @param param
|
|
* @param param
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public ChartColumn getEquipmentStatistics_1(StatisticsParam param) {
|
|
public ChartColumn getEquipmentStatistics_1(StatisticsParam param) {
|
|
BoolQueryBuilder boolQueryBuilder;
|
|
BoolQueryBuilder boolQueryBuilder;
|
|
- String startDate = param.getStartDate().replace("/","-");
|
|
|
|
- String endDate = param.getEndDate().replace("/","-");
|
|
|
|
- Date start = DateUtils.parseDate(startDate+" 00:00:00", DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss,new Date());
|
|
|
|
- Date end = DateUtils.parseDate(endDate+" 23:59:59", DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss,new Date());
|
|
|
|
|
|
+ String startDate = param.getStartDate().replace("/", "-");
|
|
|
|
+ String endDate = param.getEndDate().replace("/", "-");
|
|
|
|
+ Date start = DateUtils.parseDate(startDate + " 00:00:00", DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss, new Date());
|
|
|
|
+ Date end = DateUtils.parseDate(endDate + " 23:59:59", DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss, new Date());
|
|
TCoinOrderParam tCoinOrderParam = new TCoinOrderParam();
|
|
TCoinOrderParam tCoinOrderParam = new TCoinOrderParam();
|
|
|
|
|
|
// tCoinOrderParam.setCreateDate_start(start);
|
|
// tCoinOrderParam.setCreateDate_start(start);
|
|
tCoinOrderParam.setPayDate_start(start);
|
|
tCoinOrderParam.setPayDate_start(start);
|
|
// tCoinOrderParam.setCreateDate_end(end);
|
|
// tCoinOrderParam.setCreateDate_end(end);
|
|
tCoinOrderParam.setPayDate_end(end);
|
|
tCoinOrderParam.setPayDate_end(end);
|
|
- if(param.getClientIds() != null && param.getClientIds().size()>0){ // 设备
|
|
|
|
|
|
+ if (param.getClientIds() != null && param.getClientIds().size() > 0) { // 设备
|
|
tCoinOrderParam.setClientId_inList(param.getClientIds());
|
|
tCoinOrderParam.setClientId_inList(param.getClientIds());
|
|
}
|
|
}
|
|
- if(StringUtils.isNotEmpty(param.getAdminId())){ // 所属商家id
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(param.getAdminId())) { // 所属商家id
|
|
tCoinOrderParam.setAdminId(Long.parseLong(param.getAdminId()));
|
|
tCoinOrderParam.setAdminId(Long.parseLong(param.getAdminId()));
|
|
}
|
|
}
|
|
|
|
|
|
boolQueryBuilder = esTCoinOrderService.getParam2QueryBuilder(tCoinOrderParam);
|
|
boolQueryBuilder = esTCoinOrderService.getParam2QueryBuilder(tCoinOrderParam);
|
|
- if("1".equals(param.getChangeType())){
|
|
|
|
|
|
+ if ("1".equals(param.getChangeType())) {
|
|
// 花型统计
|
|
// 花型统计
|
|
- return getEquipmentStatistics(boolQueryBuilder,esTCoinOrderService.getTableName(),"productName.keyword");
|
|
|
|
- }else{
|
|
|
|
|
|
+ return getEquipmentStatistics(boolQueryBuilder, esTCoinOrderService.getTableName(), "productName.keyword");
|
|
|
|
+ } else {
|
|
log.info("1");
|
|
log.info("1");
|
|
- ChartColumn chartColumn = getEquipmentStatistics(boolQueryBuilder,esTCoinOrderService.getTableName(),"clientId.keyword");
|
|
|
|
|
|
+ ChartColumn chartColumn = getEquipmentStatistics(boolQueryBuilder, esTCoinOrderService.getTableName(), "clientId.keyword");
|
|
|
|
|
|
// 设置categories
|
|
// 设置categories
|
|
ArrayList<String> clientIdList = chartColumn.getCategories();
|
|
ArrayList<String> clientIdList = chartColumn.getCategories();
|
|
-// TEquipmentParam tEquipmentParam = new TEquipmentParam();
|
|
|
|
-// tEquipmentParam.setClientId_inList(clientIdList);
|
|
|
|
-// List<TEquipment> equipmentList = this.selectEntityByEqualToOption(tEquipmentParam);
|
|
|
|
|
|
|
|
ArrayList<String> categories_final = new ArrayList<>();
|
|
ArrayList<String> categories_final = new ArrayList<>();
|
|
for (String clientId : clientIdList) {
|
|
for (String clientId : clientIdList) {
|
|
-// String finalCategories = clientId.substring(0,4);
|
|
|
|
TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
|
|
TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
|
|
-// Optional<TEquipment> op = equipmentList.stream().filter(
|
|
|
|
-// e ->{
|
|
|
|
-// return StringUtils.equals(e.getClientId(),clientId);
|
|
|
|
-// }
|
|
|
|
-// ).findFirst();
|
|
|
|
-// if(op.isPresent()){
|
|
|
|
-// if(StringUtils.isNotEmpty(op.get().getName())){
|
|
|
|
-// finalCategories = op.get().getName();
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
- if(equipment!=null&&equipment.getId()!=null){
|
|
|
|
- if(StringUtils.isNotEmpty(equipment.getName())){
|
|
|
|
|
|
+ if (equipment != null && equipment.getId() != null) {
|
|
|
|
+ if (StringUtils.isNotEmpty(equipment.getName())) {
|
|
categories_final.add(equipment.getName());
|
|
categories_final.add(equipment.getName());
|
|
- }else {
|
|
|
|
- categories_final.add(equipment.getClientId().substring(equipment.getClientId().length()-6,equipment.getClientId().length()));
|
|
|
|
|
|
+ } else {
|
|
|
|
+ categories_final.add(equipment.getClientId().substring(equipment.getClientId().length() - 6, equipment.getClientId().length()));
|
|
}
|
|
}
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
categories_final.add(clientId);
|
|
categories_final.add(clientId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -364,7 +358,7 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public ChartColumn getEquipmentStatistics(BoolQueryBuilder queryBuilder,String tableName ,String termField) {
|
|
|
|
|
|
+ public ChartColumn getEquipmentStatistics(BoolQueryBuilder queryBuilder, String tableName, String termField) {
|
|
try {
|
|
try {
|
|
// 仅为名称,用以获取返回结果
|
|
// 仅为名称,用以获取返回结果
|
|
String aggregationResultName = "aggregationResult";
|
|
String aggregationResultName = "aggregationResult";
|
|
@@ -383,7 +377,7 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
termsAggregationBuilder.size(60);
|
|
termsAggregationBuilder.size(60);
|
|
termsAggregationBuilder.order(BucketOrder.compound(
|
|
termsAggregationBuilder.order(BucketOrder.compound(
|
|
//先按sales,降序排
|
|
//先按sales,降序排
|
|
- BucketOrder.aggregation(aggSumName,false)
|
|
|
|
|
|
+ BucketOrder.aggregation(aggSumName, false)
|
|
));
|
|
));
|
|
// 根据字段price 求和 sum, sales 仅为名称,用以获取返回结果
|
|
// 根据字段price 求和 sum, sales 仅为名称,用以获取返回结果
|
|
SumAggregationBuilder sumAggregationBuilder = AggregationBuilders.sum(aggSumName).field("price");
|
|
SumAggregationBuilder sumAggregationBuilder = AggregationBuilders.sum(aggSumName).field("price");
|
|
@@ -416,22 +410,18 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
ParsedSum saleNum2 = bucket.getAggregations().get(aggName_refundQuantity);
|
|
ParsedSum saleNum2 = bucket.getAggregations().get(aggName_refundQuantity);
|
|
String saleNumStr1 = format1((float) saleNum1.getValue());
|
|
String saleNumStr1 = format1((float) saleNum1.getValue());
|
|
String saleNumStr2 = format1((float) saleNum2.getValue());
|
|
String saleNumStr2 = format1((float) saleNum2.getValue());
|
|
- if(StringUtils.isEmpty(saleNumStr1)){
|
|
|
|
|
|
+ if (StringUtils.isEmpty(saleNumStr1)) {
|
|
saleNumStr1 = "1";
|
|
saleNumStr1 = "1";
|
|
}
|
|
}
|
|
chartBean.setSaleNum(Float.valueOf(saleNumStr1) - Float.valueOf(saleNumStr2));
|
|
chartBean.setSaleNum(Float.valueOf(saleNumStr1) - Float.valueOf(saleNumStr2));
|
|
-// chartBean.setSaleNum(Float.valueOf(bucket.getDocCount()));
|
|
|
|
ParsedSum sum = bucket.getAggregations().get(aggSumName);
|
|
ParsedSum sum = bucket.getAggregations().get(aggSumName);
|
|
ParsedSum refundSum = bucket.getAggregations().get(aggName_refundAmount);
|
|
ParsedSum refundSum = bucket.getAggregations().get(aggName_refundAmount);
|
|
String s1 = format1((float) sum.getValue());
|
|
String s1 = format1((float) sum.getValue());
|
|
String s2 = format1((float) refundSum.getValue());
|
|
String s2 = format1((float) refundSum.getValue());
|
|
chartBean.setSalePrice(Float.valueOf(s1) - Float.valueOf(s2));
|
|
chartBean.setSalePrice(Float.valueOf(s1) - Float.valueOf(s2));
|
|
-// chartBean.setSalePrice(Double.valueOf(sum.getValue()).intValue());
|
|
|
|
-// String s = format1((float)sum.getValue());
|
|
|
|
-// chartBean.setSalePrice(Float.valueOf(s));
|
|
|
|
chartBeanList.add(chartBean);
|
|
chartBeanList.add(chartBean);
|
|
}
|
|
}
|
|
- log.debug("chartBeanList:{}",chartBeanList);
|
|
|
|
|
|
+ log.debug("chartBeanList:{}", chartBeanList);
|
|
ChartColumn chartColumn = new ChartColumn(chartBeanList);
|
|
ChartColumn chartColumn = new ChartColumn(chartBeanList);
|
|
return chartColumn;
|
|
return chartColumn;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -439,10 +429,126 @@ public class EsTEquipmentService extends EsBaseService<TEquipment, TEquipmentPar
|
|
throw new MyException(getTableName() + " es根据条件 聚合查询 报错:" + e.getMessage());
|
|
throw new MyException(getTableName() + " es根据条件 聚合查询 报错:" + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- public static String format1(Float value){
|
|
|
|
|
|
+
|
|
|
|
+ public static String format1(Float value) {
|
|
BigDecimal bd = new BigDecimal(value);//创建一个bd对象,将要转换的值value传入构造函数
|
|
BigDecimal bd = new BigDecimal(value);//创建一个bd对象,将要转换的值value传入构造函数
|
|
bd = bd.setScale(2, RoundingMode.HALF_UP);//调用setScale方法进行数据格式化,保留两位小数,采用四舍五入规则
|
|
bd = bd.setScale(2, RoundingMode.HALF_UP);//调用setScale方法进行数据格式化,保留两位小数,采用四舍五入规则
|
|
return bd.toString(); //返回bd对象的值(转化为string形式)
|
|
return bd.toString(); //返回bd对象的值(转化为string形式)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public SellChartColumn getEquipmentPageStatistics(StatisticsParam param) {
|
|
|
|
+
|
|
|
|
+ BoolQueryBuilder boolQueryBuilder;
|
|
|
|
+ String startDate = param.getStartDate().replace("/", "-");
|
|
|
|
+ String endDate = param.getEndDate().replace("/", "-");
|
|
|
|
+ Date start = DateUtils.parseDate(startDate + " 00:00:00", DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss, new Date());
|
|
|
|
+ Date end = DateUtils.parseDate(endDate + " 23:59:59", DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss, new Date());
|
|
|
|
+
|
|
|
|
+ TCoinOrderParam tCoinOrderParam = new TCoinOrderParam();
|
|
|
|
+ tCoinOrderParam.setPayDate_start(start);
|
|
|
|
+ tCoinOrderParam.setPayDate_end(end);
|
|
|
|
+ if (param.getEquipmentIds() != null && !param.getEquipmentIds().isEmpty()) { // 设备id
|
|
|
|
+ tCoinOrderParam.setEquipmentId_inList(param.getEquipmentIds());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(param.getAdminId())) { // 所属商家id
|
|
|
|
+ tCoinOrderParam.setAdminId(Long.parseLong(param.getAdminId()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ boolQueryBuilder = esTCoinOrderService.getParam2QueryBuilder(tCoinOrderParam);
|
|
|
|
+ SellChartColumn chartColumn = getEquipmentPageStatistics(boolQueryBuilder, esTCoinOrderService.getTableName(), "equipmentId");
|
|
|
|
+
|
|
|
|
+ // 设置categories
|
|
|
|
+ ArrayList<String> equipmentIdList = chartColumn.getCategories();
|
|
|
|
+
|
|
|
|
+ ArrayList<String> categories_final = new ArrayList<>();
|
|
|
|
+ for (String equipmentId : equipmentIdList) {
|
|
|
|
+ TEquipment equipment = R.getDataIfSuccess(szwlFeign.findById(equipmentId));
|
|
|
|
+ if (equipment != null) {
|
|
|
|
+ if (StringUtils.isNotEmpty(equipment.getName())) {
|
|
|
|
+ categories_final.add(equipment.getName());
|
|
|
|
+ } else {
|
|
|
|
+ categories_final.add(equipment.getClientId().substring(equipment.getClientId().length() - 6));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ categories_final.add(equipmentId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ chartColumn.setCategories(categories_final);
|
|
|
|
+ return chartColumn;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private SellChartColumn getEquipmentPageStatistics(BoolQueryBuilder queryBuilder, String tableName, String termField) {
|
|
|
|
+ try {
|
|
|
|
+ // 仅为名称,用以获取返回结果
|
|
|
|
+ String aggregationResultName = "aggregationResult";
|
|
|
|
+ // 仅为名称,用以获取返回结果
|
|
|
|
+ String aggPayTypeResultName = "aggPayTypeResult";
|
|
|
|
+ // 仅为名称,用以获取返回结果
|
|
|
|
+ String aggSumName = "sales";
|
|
|
|
+ // 仅为名称,用以获取返回结果
|
|
|
|
+ String totalPrice = "totalPrice";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 根据字段 termField 聚合
|
|
|
|
+ TermsAggregationBuilder termsAggregationBuilder = AggregationBuilders.terms(aggregationResultName).field(termField);
|
|
|
|
+ // 聚合后 返回前30条 记录
|
|
|
|
+ termsAggregationBuilder.size(1000);
|
|
|
|
+ // 按totalPrice降序排序
|
|
|
|
+ termsAggregationBuilder.order(BucketOrder.compound(BucketOrder.aggregation(totalPrice, false)));
|
|
|
|
+ TermsAggregationBuilder payTypeAggregation = AggregationBuilders.terms(aggPayTypeResultName).field("payType");
|
|
|
|
+
|
|
|
|
+ // 根据字段price 求和 sum, sales 仅为名称,用以获取返回销售额
|
|
|
|
+ SumAggregationBuilder sumAggregationBuilder = AggregationBuilders.sum(aggSumName).field("price");
|
|
|
|
+ payTypeAggregation.subAggregation(sumAggregationBuilder);
|
|
|
|
+ termsAggregationBuilder.subAggregation(payTypeAggregation);
|
|
|
|
+
|
|
|
|
+ // 添加总价格的聚合
|
|
|
|
+ SumAggregationBuilder totalPriceAggregation = AggregationBuilders.sum(totalPrice).field("price");
|
|
|
|
+ termsAggregationBuilder.subAggregation(totalPriceAggregation);
|
|
|
|
+
|
|
|
|
+ SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
|
|
|
|
+ // 指定size为0,不返回文档 因为只需要数量
|
|
|
|
+ sourceBuilder.query(queryBuilder).aggregation(termsAggregationBuilder).size(0);
|
|
|
|
+ SearchRequest searchRequest = new SearchRequest(tableName);
|
|
|
|
+ searchRequest.source(sourceBuilder);
|
|
|
|
+ log.debug("sourceBuilder:{}", sourceBuilder);
|
|
|
|
+ SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
|
|
|
|
+ Aggregations aggregations = searchResponse.getAggregations();
|
|
|
|
+ Terms terms = aggregations.get(aggregationResultName);
|
|
|
|
+
|
|
|
|
+ List<SellChartBean> chartBeanList = new ArrayList<>();
|
|
|
|
+ for (Terms.Bucket bucket : terms.getBuckets()) {
|
|
|
|
+ SellChartBean sellChartBean = new SellChartBean();
|
|
|
|
+ sellChartBean.setCategory(bucket.getKeyAsString());
|
|
|
|
+ Terms aggPayTypeResult = bucket.getAggregations().get(aggPayTypeResultName);
|
|
|
|
+ for(Terms.Bucket bucketPayType : aggPayTypeResult.getBuckets()) {
|
|
|
|
+ // 支付方式
|
|
|
|
+ String payType = bucketPayType.getKeyAsString();
|
|
|
|
+ log.info("payType:{}", payType);
|
|
|
|
+ // 支付方式的销售额
|
|
|
|
+ ParsedSum sum = bucketPayType.getAggregations().get(aggSumName);
|
|
|
|
+ float sumValue = (float) sum.getValue();
|
|
|
|
+ log.info("sumValue:{}", sumValue);
|
|
|
|
+ if (StringUtils.equals("1", payType)) {
|
|
|
|
+ sellChartBean.setCoinNum(sumValue);
|
|
|
|
+ } else if (StringUtils.equals("2", payType)) {
|
|
|
|
+ sellChartBean.setPaperMoneyNum(sumValue);
|
|
|
|
+ } else if (StringUtils.equals("3", payType)) {
|
|
|
|
+ sellChartBean.setCoinAndPaperMoneyNum(sumValue);
|
|
|
|
+ } else if (StringUtils.equals("4", payType)) {
|
|
|
|
+ sellChartBean.setCreditCardNum(sumValue);
|
|
|
|
+ } else if (StringUtils.equals("5", payType)) {
|
|
|
|
+ sellChartBean.setElectronicNum(sumValue);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ chartBeanList.add(sellChartBean);
|
|
|
|
+ }
|
|
|
|
+ log.debug("chartBeanList:{}", chartBeanList);
|
|
|
|
+ SellChartColumn sellChartColumn = new SellChartColumn(chartBeanList);
|
|
|
|
+ return sellChartColumn;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("{} es根据条件 聚合查询 报错:{}", getTableName(), e);
|
|
|
|
+ throw new MyException(getTableName() + " es根据条件 聚合查询 报错:" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|