Compare commits

..

2 Commits

Author SHA1 Message Date
luyya 2c65144b04 宣城同步宿州历史轨迹查询不到数据问题 2025-06-12 09:58:51 +08:00
luyya 2f1536afd9 宣城同步宿州的一些改动 2025-06-11 10:07:38 +08:00
9 changed files with 152 additions and 65 deletions

View File

@ -3,6 +3,8 @@ package org.dromara.location.config;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider; import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
@ -66,7 +68,7 @@ public class ElasticsearchConfig {
RestClientBuilder builder = RestClient.builder(httpHost); RestClientBuilder builder = RestClient.builder(httpHost);
// 设置用户名、密码 // 设置用户名、密码
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
// credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password)); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
// 连接延时配置 // 连接延时配置
builder.setRequestConfigCallback(requestConfigBuilder -> { builder.setRequestConfigCallback(requestConfigBuilder -> {
requestConfigBuilder.setConnectTimeout(connectTimeOut); requestConfigBuilder.setConnectTimeout(connectTimeOut);

View File

@ -30,12 +30,7 @@ public class ElasticSearchController extends BaseController {
String startTime = params.get("startTime").toString(); String startTime = params.get("startTime").toString();
String endTime = params.get("endTime").toString(); String endTime = params.get("endTime").toString();
String deviceType = params.get("deviceType").toString(); String deviceType = params.get("deviceType").toString();
List<Map> gpsInfoEntities = null; List<Map> gpsInfoEntities = searchService.searchCar(deviceCode, startTime, endTime,deviceType);
try {
gpsInfoEntities = searchService.searchCar(deviceCode, startTime, endTime,deviceType);
}catch (RuntimeException e){
return R.fail(500,e.getMessage());
}
return R.ok(gpsInfoEntities); return R.ok(gpsInfoEntities);
} }

View File

@ -4,8 +4,8 @@ import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.location.service.ISearchService; import org.dromara.location.service.ISearchService;
import org.dromara.system.api.RemoteDictService; import org.dromara.system.api.RemoteDictService;
@ -25,6 +25,10 @@ import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -40,6 +44,7 @@ import java.util.function.Consumer;
@RequiredArgsConstructor @RequiredArgsConstructor
@Service @Service
@Slf4j
public class SearchServiceImpl implements ISearchService { public class SearchServiceImpl implements ISearchService {
@Autowired @Autowired
@ -52,28 +57,71 @@ public class SearchServiceImpl implements ISearchService {
@Override @Override
public List<Map> searchCar(String deviceCode, String startTime, String endTime,String deviceType) throws RuntimeException{ public List<Map> searchCar(String deviceCode, String startTime, String endTime,String deviceType){
List<Map> sourceList = new ArrayList<Map>(); List<Map> sourceList = new ArrayList<Map>();
List<String> esIndexByTime = findEsIndexByTime(startTime, endTime); List<String> esIndexByTime = findEsIndexByTime(startTime, endTime);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); log.info("查询使用的索引列表: {}", esIndexByTime); // 添加日志输出
DateTime startDate = DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss");
DateTime endDate = DateUtil.parse(endTime, "yyyy-MM-dd HH:mm:ss");
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery()
// 匹配第一个 .must(QueryBuilders.termQuery("deviceCode", deviceCode))
TermQueryBuilder termTerminalBuilder1 = QueryBuilders.termQuery("deviceCode", deviceCode); .must(QueryBuilders.termQuery("deviceType", deviceType))
// 匹配第二个 .must(QueryBuilders.rangeQuery("gpsTime")
TermQueryBuilder termTerminalBuilder2 = QueryBuilders.termQuery("deviceType", deviceType); .format("yyyy-MM-dd HH:mm:ss")
.gte(startTime)
boolBuilder.must(termTerminalBuilder1); .lte(endTime));
log.info("查询条件: deviceCode={}, deviceType={}, start={}, end={}",
boolBuilder.must(termTerminalBuilder2); deviceCode, deviceType, startTime, endTime);
System.out.print(format.format(startDate));
boolBuilder.must(QueryBuilders.rangeQuery("gpsTime")
.gte(format.format(startDate))
.lte(format.format(endDate)) );
// 执行滚动查询
Scroll scroll = new Scroll(TimeValue.timeValueMinutes(1L)); Scroll scroll = new Scroll(TimeValue.timeValueMinutes(1L));
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder()
.query(boolBuilder)
.sort("gpsTime", SortOrder.ASC)
.size(5000);
SearchRequest rq = new SearchRequest()
.indices(esIndexByTime.toArray(new String[0]))
.source(sourceBuilder)
.scroll(scroll)
.indicesOptions(IndicesOptions.lenientExpandOpen());
// 添加到构建查询后
String dsl = sourceBuilder.toString();
log.info("最终DSL查询语句:\n{}", dsl);
try {
SearchResponse rp = restHighLevelClient.search(rq, RequestOptions.DEFAULT);
log.info("ES返回总命中数: {}", rp.getHits().getTotalHits()); // 关键日志
String scrollId = rp.getScrollId();
SearchHit[] hits = rp.getHits().getHits();
while (hits != null && hits.length > 0) {
for (SearchHit hit : hits) {
sourceList.add(hit.getSourceAsMap());
}
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId)
.scroll(scroll);
rp = restHighLevelClient.scroll(scrollRequest, RequestOptions.DEFAULT);
hits = rp.getHits().getHits();
scrollId = rp.getScrollId(); // 更新scrollId
}
// 清理滚动
//清除滚屏
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollId);//也可以选择setScrollIds()将多个scrollId一起使用
ClearScrollResponse clearScrollResponse = null;
try {
clearScrollResponse = restHighLevelClient.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
boolean succeeded = clearScrollResponse.isSucceeded();
} catch (IOException e) {
log.error("ES查询异常", e);
}
return sourceList;
/* Scroll scroll = new Scroll(TimeValue.timeValueMinutes(1L));
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(boolBuilder).sort("gpsTime",SortOrder.ASC).size(5000); sourceBuilder.query(boolBuilder).sort("gpsTime",SortOrder.ASC).size(5000);
SearchRequest rq = new SearchRequest(); SearchRequest rq = new SearchRequest();
@ -86,7 +134,9 @@ public class SearchServiceImpl implements ISearchService {
// SearchResponse rp = null; // SearchResponse rp = null;
try { try {
SearchResponse rp = restHighLevelClient.search(rq,RequestOptions.DEFAULT); SearchResponse rp = restHighLevelClient.search(rq,RequestOptions.DEFAULT);
log.info("查询轨迹结果={}", rp.getHits());
SearchHit[] searchHits = rp.getHits().getHits(); SearchHit[] searchHits = rp.getHits().getHits();
log.info("查询轨迹结果searchHits={}",searchHits.length);
for (SearchHit searchHit : searchHits) { for (SearchHit searchHit : searchHits) {
Map sourceAsMap = searchHit.getSourceAsMap(); Map sourceAsMap = searchHit.getSourceAsMap();
sourceList.add(sourceAsMap); sourceList.add(sourceAsMap);
@ -94,6 +144,7 @@ public class SearchServiceImpl implements ISearchService {
//遍历搜索命中的数据,直到没有数据 //遍历搜索命中的数据,直到没有数据
String scrollId = rp.getScrollId(); String scrollId = rp.getScrollId();
while (searchHits != null && searchHits.length > 0) { while (searchHits != null && searchHits.length > 0) {
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId);
scrollRequest.scroll(scroll); scrollRequest.scroll(scroll);
@ -126,7 +177,7 @@ public class SearchServiceImpl implements ISearchService {
e.printStackTrace(); e.printStackTrace();
} }
return sourceList; return sourceList;*/
} }
@Override @Override

View File

@ -72,6 +72,7 @@ public class TDeviceController extends BaseController {
* device * device
*/ */
@SaCheckPermission("system:device:export") @SaCheckPermission("system:device:export")
@Log(title = "device", businessType = BusinessType.EXPORT) @Log(title = "device", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public void export(TDeviceBo bo, HttpServletResponse response) { public void export(TDeviceBo bo, HttpServletResponse response) {

View File

@ -40,6 +40,8 @@ public class SysDept extends TenantEntity {
*/ */
private String deptName; private String deptName;
private String shortName;
/** /**
* *
@ -79,4 +81,6 @@ public class SysDept extends TenantEntity {
private String fullName; private String fullName;
private String isVisible;
} }

View File

@ -24,6 +24,7 @@ public class SysDeptBo extends BaseEntity {
/** /**
* id * id
*/ */
@Size(min = 0, max = 12, message = "部门机构代码长度不能超过{max}个字符")
private String deptId; private String deptId;
/** /**
@ -38,6 +39,9 @@ public class SysDeptBo extends BaseEntity {
@Size(min = 0, max = 30, message = "部门名称长度不能超过{max}个字符") @Size(min = 0, max = 30, message = "部门名称长度不能超过{max}个字符")
private String deptName; private String deptName;
@NotBlank(message = "部门简称不能为空")
private String shortName;
/** /**
* *
*/ */
@ -75,4 +79,6 @@ public class SysDeptBo extends BaseEntity {
private String fullName; private String fullName;
private String isVisible;
} }

View File

@ -52,6 +52,8 @@ public class SysDeptVo implements Serializable {
@ExcelProperty(value = "部门名称") @ExcelProperty(value = "部门名称")
private String deptName; private String deptName;
private String shortName;
/** /**
* *
*/ */
@ -93,6 +95,8 @@ public class SysDeptVo implements Serializable {
@ExcelDictFormat(dictType = "sys_normal_disable") @ExcelDictFormat(dictType = "sys_normal_disable")
private String status; private String status;
private String isVisible;
/** /**
* *
*/ */

View File

@ -16,8 +16,10 @@ import org.dromara.common.excel.core.ExcelListener;
import org.dromara.common.excel.core.ExcelResult; import org.dromara.common.excel.core.ExcelResult;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.domain.bo.TDeviceBo; import org.dromara.system.domain.bo.TDeviceBo;
import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.domain.vo.TDeviceImportVo; import org.dromara.system.domain.vo.TDeviceImportVo;
import org.dromara.system.domain.vo.TDeviceVo; import org.dromara.system.domain.vo.TDeviceVo;
import org.dromara.system.service.ISysDeptService;
import org.dromara.system.service.ITDeviceService; import org.dromara.system.service.ITDeviceService;
import java.util.List; import java.util.List;
@ -27,6 +29,8 @@ public class TDeviceImportListener extends AnalysisEventListener<TDeviceImportVo
private final ITDeviceService deviceService; private final ITDeviceService deviceService;
private final ISysDeptService deptService;
private final Boolean isUpdateSupport; private final Boolean isUpdateSupport;
@ -37,42 +41,60 @@ public class TDeviceImportListener extends AnalysisEventListener<TDeviceImportVo
public TDeviceImportListener(Boolean isUpdateSupport) { public TDeviceImportListener(Boolean isUpdateSupport) {
this.deviceService = SpringUtils.getBean(ITDeviceService.class); this.deviceService = SpringUtils.getBean(ITDeviceService.class);
this.deptService = SpringUtils.getBean(ISysDeptService.class);
this.isUpdateSupport = isUpdateSupport; this.isUpdateSupport = isUpdateSupport;
} }
@Override @Override
public void invoke(TDeviceImportVo deviceImportVo, AnalysisContext context) { public void invoke(TDeviceImportVo deviceImportVo, AnalysisContext context) {
TDeviceVo deviceVo = this.deviceService.queryByDeviceCode(deviceImportVo.getDeviceCode());
try { if (null != deviceImportVo.getDeviceCode() && deviceImportVo.getDeviceCode().contains("设备编码为国标编码")){
// 验证是否存在这个设备 failureNum = 1;
if (ObjectUtil.isNull(deviceVo)) { failureMsg.append("请删除Excel中提示必须删除的行后重新导入");
TDeviceBo deviceBo = BeanUtil.toBean(deviceImportVo, TDeviceBo.class); }else {
ValidatorUtils.validate(deviceBo); String deviceCode = deviceImportVo.getDeviceCode().replaceAll("[\\p{Zs}\\s]", "");
deviceService.insertByBo(deviceBo); TDeviceVo deviceVo = this.deviceService.queryByDeviceCode(deviceCode);
successNum++; try {
successMsg.append("<br/>").append(successNum).append("、设备 ").append(deviceBo.getDeviceCode()).append(" 导入成功"); // 验证是否存在这个设备
} else if (isUpdateSupport) { if (ObjectUtil.isNull(deviceVo)) {
Long id = deviceVo.getId(); deviceImportVo.setDeviceCode(deviceCode);
TDeviceBo deviceBo = BeanUtil.toBean(deviceVo, TDeviceBo.class); SysDeptVo deptVo = deptService.selectDeptById(deviceImportVo.getZzjgdm());
deviceBo.setId(id); if(null != deptVo){
ValidatorUtils.validate(deviceBo); deviceImportVo.setZzjgmc(deptVo.getShortName());
deviceService.updateByBo(deviceBo); }
successNum++; TDeviceBo deviceBo = BeanUtil.toBean(deviceImportVo, TDeviceBo.class);
successMsg.append("<br/>").append(successNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 更新成功"); ValidatorUtils.validate(deviceBo);
} else { deviceService.insertByBo(deviceBo);
successNum++;
successMsg.append("<br/>").append(successNum).append("、设备 ").append(deviceBo.getDeviceCode()).append(" 导入成功");
} else if (isUpdateSupport) {
Long id = deviceVo.getId();
SysDeptVo deptVo = deptService.selectDeptById(deviceVo.getZzjgdm());
if(null != deptVo){
deviceVo.setZzjgmc(deptVo.getShortName());
}
TDeviceBo deviceBo = BeanUtil.toBean(deviceVo, TDeviceBo.class);
deviceBo.setId(id);
ValidatorUtils.validate(deviceBo);
deviceService.updateByBo(deviceBo);
successNum++;
successMsg.append("<br/>").append(successNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 更新成功");
} else {
failureNum++;
failureMsg.append("<br/>").append(failureNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 已存在");
}
} catch (Exception e) {
failureNum++; failureNum++;
failureMsg.append("<br/>").append(failureNum).append("、设备 ").append(deviceImportVo.getDeviceCode()).append(" 已存在"); String msg = "<br/>" + failureNum + "、设备 " + HtmlUtil.cleanHtmlTag(deviceImportVo.getDeviceCode()) + " 导入失败:";
String message = e.getMessage();
if (e instanceof ConstraintViolationException cvException) {
message = StreamUtils.join(cvException.getConstraintViolations(), ConstraintViolation::getMessage, ", ");
}
failureMsg.append(msg).append(message);
log.error(msg, e);
} }
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、设备 " + HtmlUtil.cleanHtmlTag(deviceImportVo.getDeviceCode()) + " 导入失败:";
String message = e.getMessage();
if (e instanceof ConstraintViolationException cvException) {
message = StreamUtils.join(cvException.getConstraintViolations(), ConstraintViolation::getMessage, ", ");
}
failureMsg.append(msg).append(message);
log.error(msg, e);
} }
} }
@Override @Override

View File

@ -70,7 +70,7 @@
</if> </if>
group by SUBSTRING(zzjgdm,1,8)) a group by SUBSTRING(zzjgdm,1,8)) a
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8) on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8)
where `status` = '0' and del_flag =0 and parent_id = '341800000000' and dept_id like '341800%' where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '341800000000' and dept_id like '341800%'
union union
@ -92,7 +92,7 @@
</if> </if>
group by SUBSTRING(zzjgdm,1,6)) a group by SUBSTRING(zzjgdm,1,6)) a
on SUBSTRING(d.dept_id,1,6) = SUBSTRING(a.zzjgdm,1,6) on SUBSTRING(d.dept_id,1,6) = SUBSTRING(a.zzjgdm,1,6)
where `status` = '0' and del_flag =0 and parent_id = '341800000000' and dept_id not like '341800%' where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '341800000000' and dept_id not like '341800%'
union union
<!--派出所等三级四级机构--> <!--派出所等三级四级机构-->
@ -113,7 +113,7 @@
</if> </if>
group by SUBSTRING(zzjgdm,1,8)) a group by SUBSTRING(zzjgdm,1,8)) a
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8) on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8)
where `status` = '0' and del_flag =0 and parent_id != '341800000000' and dept_id not like '341800%' and dept_id like '%0000' where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000' and parent_id != '0' and dept_id like '%0000'
<!--大队等三级四级机构--> <!--大队等三级四级机构-->
UNION UNION
select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
@ -133,7 +133,8 @@
</if> </if>
group by SUBSTRING(zzjgdm,1,10)) a group by SUBSTRING(zzjgdm,1,10)) a
on SUBSTRING(d.dept_id,1,10) = SUBSTRING(a.zzjgdm,1,10) on SUBSTRING(d.dept_id,1,10) = SUBSTRING(a.zzjgdm,1,10)
where `status` = '0' and del_flag =0 and parent_id != '341800000000' and parent_id != '0' and dept_id like '341800%' and dept_id like '%00' where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000'
and parent_id != '0' and dept_id not like '%0000' and dept_id like '%00'
union union
<!--四级机构--> <!--四级机构-->
@ -154,7 +155,7 @@
</if> </if>
group by zzjgdm) a group by zzjgdm) a
on d.dept_id = a.zzjgdm on d.dept_id = a.zzjgdm
where `status` = '0' and del_flag =0 and LENGTH(ancestors) = 40 where `status` = '0' and del_flag =0 and is_visible = '1' and dept_id not like '%00' and LENGTH(ancestors) >= 40
) a ) a
order by a.deptId asc order by a.deptId asc
</select> </select>
@ -175,7 +176,7 @@
LEFT JOIN LEFT JOIN
(select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid =1 group by SUBSTRING(zzjgdm,1,8)) a (select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid =1 group by SUBSTRING(zzjgdm,1,8)) a
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8) on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8)
where `status` = '0' and del_flag =0 and parent_id = '340100000000' and dept_id like '340100%' where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '340100000000' and dept_id like '340100%'
union union
@ -187,7 +188,7 @@
LEFT JOIN LEFT JOIN
(select substring(zzjgdm,1,6) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid =1 group by SUBSTRING(zzjgdm,1,6)) a (select substring(zzjgdm,1,6) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid =1 group by SUBSTRING(zzjgdm,1,6)) a
on SUBSTRING(d.dept_id,1,6) = SUBSTRING(a.zzjgdm,1,6) on SUBSTRING(d.dept_id,1,6) = SUBSTRING(a.zzjgdm,1,6)
where `status` = '0' and del_flag =0 and parent_id = '340100000000' and dept_id not like '340100%' where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id = '340100000000' and dept_id not like '340100%'
union union
<!--派出所等三级四级机构--> <!--派出所等三级四级机构-->
@ -198,7 +199,7 @@
LEFT JOIN LEFT JOIN
(select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by SUBSTRING(zzjgdm,1,8)) a (select substring(zzjgdm,1,8) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by SUBSTRING(zzjgdm,1,8)) a
on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8) on SUBSTRING(d.dept_id,1,8) = SUBSTRING(a.zzjgdm,1,8)
where `status` = '0' and del_flag =0 and parent_id != '340100000000' and dept_id not like '340100%' and dept_id like '%0000' where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000' and parent_id != '0' and dept_id like '%0000'
<!--大队等三级四级机构--> <!--大队等三级四级机构-->
UNION UNION
select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d select dept_id as deptId,short_name as deptName,parent_id as parentId,IFNULL(onlineCount,0) as onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
@ -208,18 +209,19 @@
LEFT JOIN LEFT JOIN
(select substring(zzjgdm,1,10) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by SUBSTRING(zzjgdm,1,10)) a (select substring(zzjgdm,1,10) as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by SUBSTRING(zzjgdm,1,10)) a
on SUBSTRING(d.dept_id,1,10) = SUBSTRING(a.zzjgdm,1,10) on SUBSTRING(d.dept_id,1,10) = SUBSTRING(a.zzjgdm,1,10)
where `status` = '0' and del_flag =0 and parent_id != '340100000000' and parent_id != '0' and dept_id like '340100%' and dept_id like '%00' where `status` = '0' and del_flag =0 and is_visible = '1' and parent_id != '341800000000'
and parent_id != '0' and dept_id not like '%0000' and dept_id like '%00'
union union
<!--四级机构--> <!--四级机构-->
select dept_id as deptId,dept_name as deptName,parent_id,IFNULL(onlineCount,0) onlineCount,IFNULL(allCount,0) as allCount from sys_dept d select dept_id as deptId,short_name as deptName,parent_id,IFNULL(onlineCount,0) onlineCount,IFNULL(allCount,0) as allCount from sys_dept d
left JOIN left JOIN
(select zzjgdm ,count(*) as onlineCount from t_device_redis where online =1 and device_type = #{deviceType} group by zzjgdm) o (select zzjgdm ,count(*) as onlineCount from t_device_redis where online =1 and device_type = #{deviceType} group by zzjgdm) o
on d.dept_id = o.zzjgdm on d.dept_id = o.zzjgdm
LEFT JOIN LEFT JOIN
(select zzjgdm as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by zzjgdm) a (select zzjgdm as zzjgdm ,count(*) as allCount from t_device where device_type = #{deviceType} and valid = 1 group by zzjgdm) a
on d.dept_id = a.zzjgdm on d.dept_id = a.zzjgdm
where `status` = '0' and del_flag =0 and LENGTH(ancestors) = 40 where `status` = '0' and del_flag =0 and is_visible = '1' and dept_id not like '%00' and LENGTH(ancestors) >= 40
) count_temp ) count_temp
<where> <where>
<if test="deptId != null and deptId != ''"> <if test="deptId != null and deptId != ''">