模糊查询优化

master
liuguijing 2 years ago
parent 2445cb2513
commit 48bdbfd220

@ -32,7 +32,7 @@ public class TerminalController extends BaseController {
@ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")}) @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")})
@RequestMapping("/getTerminalList") @RequestMapping("/getTerminalList")
@Log(title = "获取设备列表", type = "查询") @Log(title = "获取设备列表", type = "查询")
public ResponseReult<TerminalListModel> getTerminalList(@RequestBody @Validated PageVo vo) { public ResponseReult<TerminalListModel> getTerminalList(@RequestBody @Validated TerminalSelectVo vo) {
ServiceBody<TerminalListModel> serviceBody = terminalService.getTerminalList(vo); ServiceBody<TerminalListModel> serviceBody = terminalService.getTerminalList(vo);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) { if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
return ResponseReult.success(serviceBody.getData()); return ResponseReult.success(serviceBody.getData());
@ -211,4 +211,5 @@ public class TerminalController extends BaseController {
} }
} }
} }

@ -0,0 +1,27 @@
package com.shxy.xymanager_common.dto;
import lombok.Data;
@Data
public class DyLineAndTowertDto {
private Integer dyId;
private String dyName;
private Integer dyValue;
private Integer lineId;
private String lineName;
private String bsManufacturer;
private Integer dyLevelId;
private Integer towerId;
private String towerName;
}

@ -38,6 +38,9 @@ public class TerminalUtils {
* @param lastHeartbeat * @param lastHeartbeat
*/ */
public static boolean judgeTerminalStatus(BigInteger lastHeartbeat) { public static boolean judgeTerminalStatus(BigInteger lastHeartbeat) {
if (lastHeartbeat == null) {
return false;
}
long time = MyDateUtils.TimeSecond2MillSecond(lastHeartbeat.longValue()); long time = MyDateUtils.TimeSecond2MillSecond(lastHeartbeat.longValue());
DateTime date = MyDateUtils.date(time); DateTime date = MyDateUtils.date(time);
long between = MyDateUtils.between(MyDateUtils.getNowDate(), date, DateUnit.MINUTE); long between = MyDateUtils.between(MyDateUtils.getNowDate(), date, DateUnit.MINUTE);

@ -12,7 +12,7 @@ import java.util.List;
@ApiModel(value = "线路杆塔通道和时间查询", description = "线路杆塔通道和时间查询") @ApiModel(value = "线路杆塔通道和时间查询", description = "线路杆塔通道和时间查询")
public class LineAndGtAndChannelVo { public class LineAndGtAndChannelVo {
@ApiModelProperty(value = "查询类型", example = "1--电压 2--线路 3--杆塔 4--通道") @ApiModelProperty(value = "查询类型", example = "1--电压 2--线路 3--杆塔 4--装置 5--通道")
private Integer type; private Integer type;
@ApiModelProperty(value = "编号", example = "123455") @ApiModelProperty(value = "编号", example = "123455")

@ -0,0 +1,34 @@
package com.shxy.xymanager_common.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.Min;
@Data
@Validated
@ApiModel(value = "装置查询对象", description = "装置查询对象描述")
public class TerminalSelectVo {
@ApiModelProperty(value = "电压编号", example = "123455")
private Integer dyid;
@ApiModelProperty(value = "装置编号", example = "123455")
private Integer lineid;
@ApiModelProperty(value = "杆塔编号", example = "123455")
private Integer towerid;
@ApiModelProperty(value = "搜索内容", example = "搜索内容")
private String search;
@Min(value = 1, message = "分页位置最小从1开始")
@ApiModelProperty(value = "分页位置从1开始", required = true, example = "1")
private int pageindex;
@Min(value = 1, message = "分页大小最小为1")
@ApiModelProperty(value = "分页大小", required = true, example = "1")
private int pagesize;
}

@ -3,6 +3,7 @@ package com.shxy.xymanager_dao.dao;
import com.shxy.xymanager_common.dto.DyAndLineAndTowerAndTermDto; import com.shxy.xymanager_common.dto.DyAndLineAndTowerAndTermDto;
import com.shxy.xymanager_common.dto.DyLineAndTerminalNoHeartDto; import com.shxy.xymanager_common.dto.DyLineAndTerminalNoHeartDto;
import com.shxy.xymanager_common.dto.DyLineAndTerminalWithHeartDto; import com.shxy.xymanager_common.dto.DyLineAndTerminalWithHeartDto;
import com.shxy.xymanager_common.dto.DyLineAndTowertDto;
import com.shxy.xymanager_common.entity.DyLevel; import com.shxy.xymanager_common.entity.DyLevel;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -11,7 +12,9 @@ import java.util.List;
public interface DyLevelDao { public interface DyLevelDao {
List<DyAndLineAndTowerAndTermDto> selectDyAndLineAndTowerAnTermList(@Param("dyid") Integer dyid, @Param("lineid") Integer lineid, @Param("towerid") Integer towerid, @Param("termid") Integer termid,@Param("status") Integer status); List<DyAndLineAndTowerAndTermDto> selectDyAndLineAndTowerAnTermList(@Param("dyid") Integer dyid, @Param("lineid") Integer lineid, @Param("towerid") Integer towerid, @Param("termid") Integer termid, @Param("status") Integer status);
List<DyLineAndTowertDto> selectDyAndLineAndTowerList(@Param("dyid") Integer dyid, @Param("lineid") Integer lineid, @Param("towerid") Integer towerid, @Param("search") String search);
int deleteByPrimaryKey(Integer id); int deleteByPrimaryKey(Integer id);

@ -20,7 +20,7 @@ public interface TerminalsDao {
List<ChannelAndTermDto> selectChannelAndTermList(@Param("status") Integer status); List<ChannelAndTermDto> selectChannelAndTermList(@Param("status") Integer status);
List<TerminalsAndStatusDto> selectTermAndStatusList( @Param("status") Integer status); List<TerminalsAndStatusDto> selectTermAndStatusList(@Param("status") Integer status, @Param("towerid") List<Integer> towerid,@Param("search") String search);
Terminals selectByCmdid(@Param("cmdid") String cmdid, @Param("status") Integer status); Terminals selectByCmdid(@Param("cmdid") String cmdid, @Param("status") Integer status);

@ -74,6 +74,19 @@
</collection> </collection>
</resultMap> </resultMap>
<resultMap id="DyAndLineAndTowerMap" type="com.shxy.xymanager_common.dto.DyLineAndTowertDto">
<result column="dyid" jdbcType="INTEGER" property="dyId"/>
<result column="dyname" jdbcType="VARCHAR" property="dyName"/>
<result column="dyvalue" jdbcType="INTEGER" property="dyValue"/>
<result column="line_id" jdbcType="INTEGER" property="lineId"/>
<result column="line_name" jdbcType="VARCHAR" property="lineName"/>
<result column="bs_manufacturer" jdbcType="VARCHAR" property="bsManufacturer"/>
<result column="dy_level_id" jdbcType="INTEGER" property="dyLevelId"/>
<result column="term_id" jdbcType="INTEGER" property="towerId"/>
<result column="cmdid" jdbcType="VARCHAR" property="towerName"/>
</resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, name, dy_value, status, create_time, update_time id, name, dy_value, status, create_time, update_time
</sql> </sql>
@ -128,6 +141,38 @@
</where> </where>
</select> </select>
<select id="selectDyAndLineAndTowerList" resultMap="DyAndLineAndTowerMap">
select
a.id as dyid,
a.name as dyname,
a.dy_value as dyvalue,
b.id as line_id,
b.name as line_name,
b.bs_manufacturer as bs_manufacturer,
b.dy_level_id as dy_level_id,
c.id as tower_id,
c.name as tower_name
from ((dy_level a left join `lines` b on a.id = b.dy_level_id )
left join towers c on c.line_id = b.id )
<where>
true
<if test="dyid != null">
and a.id = #{dyid}
</if>
<if test="lineid != null">
and b.id = #{lineid}
</if>
<if test="towerid != null">
and c.id = #{towerid}
</if>
<if test="search != null">
and ( b.name like "%"#{search}"%" or c.name like "%"#{search}"%")
</if>
</where>
</select>
<select id="selectTreeList" resultMap="LineAndTerminalMap"> <select id="selectTreeList" resultMap="LineAndTerminalMap">
select select
a.id as id, a.id as id,

@ -50,7 +50,10 @@
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from `lines` from `lines`
where status = #{status} where true
<if test="status != null">
and status = #{status}
</if>
<if test="dyid != null"> <if test="dyid != null">
and dy_level_id = #{dyid} and dy_level_id = #{dyid}
</if> </if>

@ -144,9 +144,16 @@
b.last_heartbeat as last_heartbeat b.last_heartbeat as last_heartbeat
from from
(terminals a left join terminal_status b on a.id = b.term_id ) (terminals a left join terminal_status b on a.id = b.term_id )
<if test="status != null"> <where>
where a.status = #{status} true
</if> <if test="status != null">
and a.status = #{status}
</if>
<if test="search != null">
and a.cmdid like "%"#{search}"%"
</if>
</where>
order by a.create_time desc order by a.create_time desc
</select> </select>

@ -20,6 +20,7 @@ import com.shxy.xymanager_common.page.PageUtils;
import com.shxy.xymanager_common.util.TerminalUtils; import com.shxy.xymanager_common.util.TerminalUtils;
import com.shxy.xymanager_common.vo.*; import com.shxy.xymanager_common.vo.*;
import com.shxy.xymanager_dao.dao.TerminalChannelsDao; import com.shxy.xymanager_dao.dao.TerminalChannelsDao;
import com.shxy.xymanager_dao.dao.TerminalPhotoDao;
import com.shxy.xymanager_dao.dao.TerminalStatusDao; import com.shxy.xymanager_dao.dao.TerminalStatusDao;
import com.shxy.xymanager_service.cache.XyCache; import com.shxy.xymanager_service.cache.XyCache;
import com.shxy.xymanager_service.service.TerminalChannelService; import com.shxy.xymanager_service.service.TerminalChannelService;
@ -47,6 +48,9 @@ public class TerminalChannelServiceImpl implements TerminalChannelService {
@Autowired @Autowired
TerminalStatusDao terminalStatusDao; TerminalStatusDao terminalStatusDao;
@Autowired
TerminalPhotoDao terminalPhotoDao;
/** /**
* *
* *

@ -10,6 +10,7 @@ import com.github.pagehelper.PageInfo;
import com.shxy.xymanager_common.bean.ServiceBody; import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.constant.Constants; import com.shxy.xymanager_common.constant.Constants;
import com.shxy.xymanager_common.dto.*; import com.shxy.xymanager_common.dto.*;
import com.shxy.xymanager_common.entity.Lines;
import com.shxy.xymanager_common.entity.TerminalChannelMapper; import com.shxy.xymanager_common.entity.TerminalChannelMapper;
import com.shxy.xymanager_common.entity.TerminalStatus; import com.shxy.xymanager_common.entity.TerminalStatus;
import com.shxy.xymanager_common.entity.Terminals; import com.shxy.xymanager_common.entity.Terminals;
@ -65,6 +66,9 @@ public class TerminalServiceImpl implements TerminalService {
@Autowired @Autowired
TerminalStatusDao terminalStatusDao; TerminalStatusDao terminalStatusDao;
@Autowired
LinesDao linesDao;
@Autowired @Autowired
CacheService cacheService; CacheService cacheService;
@ -81,18 +85,50 @@ public class TerminalServiceImpl implements TerminalService {
* @return * @return
*/ */
@Override @Override
public ServiceBody<TerminalListModel> getTerminalList(PageVo vo) { public ServiceBody<TerminalListModel> getTerminalList(TerminalSelectVo vo) {
Map<Integer, TowerDto> towerMap = cacheService.getTowerMap();
Map<Integer, TermAndChannelDto> termAndChannelMap = cacheService.getTermAndChannelMap();
Integer dyid = vo.getDyid();
Integer lineid = vo.getLineid();
Integer tower = vo.getTowerid();
String search = vo.getSearch();
if (StrUtil.isEmpty(search)) {
search = null;
}
List<DyLineAndTowertDto> dyLineAndTowertDtos = new ArrayList<>();
if (dyid == null || dyid.intValue() == -1) {
tower = null;
} else {
if (lineid == null || lineid.intValue() == -1) {
dyLineAndTowertDtos = dyLevelDao.selectDyAndLineAndTowerList(dyid, null, null,search);
} else {
if (tower == null || tower.intValue() == -1) {
dyLineAndTowertDtos = dyLevelDao.selectDyAndLineAndTowerList(dyid, lineid, null,search);
} else {
dyLineAndTowertDtos = dyLevelDao.selectDyAndLineAndTowerList(dyid, lineid, tower,search);
}
}
}
List<TerminalsAndStatusDto> list2 = new ArrayList<>();
TerminalListModel model = new TerminalListModel(); TerminalListModel model = new TerminalListModel();
int pageindex = vo.getPageindex(); int pageindex = vo.getPageindex();
int pagesize = vo.getPagesize(); int pagesize = vo.getPagesize();
PageUtils.SetPage(pageindex, pagesize); PageUtils.SetPage(pageindex, pagesize);
List<TerminalsAndStatusDto> list2 = terminalsDao.selectTermAndStatusList(null); if (CollectionUtil.isNotEmpty(dyLineAndTowertDtos)) {
ArrayList<Integer> toweridlist = new ArrayList<>();
for (DyLineAndTowertDto item : dyLineAndTowertDtos) {
toweridlist.add(item.getTowerId());
}
list2 = terminalsDao.selectTermAndStatusList(null, toweridlist,search);
} else {
list2 = terminalsDao.selectTermAndStatusList(null, null,search);
}
boolean empty = CollectionUtil.isEmpty(list2); boolean empty = CollectionUtil.isEmpty(list2);
if (empty) { if (empty) {
model.setList(new ArrayList<>()); model.setList(new ArrayList<>());
} else { } else {
Map<Integer, TowerDto> towerMap = cacheService.getTowerMap();
Map<Integer, TermAndChannelDto> termAndChannelMap = cacheService.getTermAndChannelMap();
ArrayList<TerminalListModel.TerminalsBean> beanlist = new ArrayList<>(); ArrayList<TerminalListModel.TerminalsBean> beanlist = new ArrayList<>();
for (TerminalsAndStatusDto item : list2) { for (TerminalsAndStatusDto item : list2) {
TerminalListModel.TerminalsBean terminalsBean = new TerminalListModel.TerminalsBean(); TerminalListModel.TerminalsBean terminalsBean = new TerminalListModel.TerminalsBean();
@ -466,5 +502,6 @@ public class TerminalServiceImpl implements TerminalService {
} }
return Asserts.success(model); return Asserts.success(model);
} }
} }

@ -15,7 +15,7 @@ public interface TerminalService {
* *
* @return * @return
*/ */
ServiceBody<TerminalListModel> getTerminalList(PageVo vo); ServiceBody<TerminalListModel> getTerminalList(TerminalSelectVo vo);
/** /**
* *
@ -96,4 +96,5 @@ public interface TerminalService {
* @return * @return
*/ */
ServiceBody<TermStatusModel> getTermStatus(Integer termId); ServiceBody<TermStatusModel> getTermStatus(Integer termId);
} }

Loading…
Cancel
Save