实体类:
package com.byx.communitycontrol.common.entity.baseinfo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 点位信息
**/
@Data
@TableName(value = "T_DWXX")
public class PointInfo implements Serializable {
/**
* 相机编码
*/
@TableField(value = "CAMERAINDEXCODE")
private String cameraIndexCode;
/**
* 点位名称
*/
@TableField(value = "NAME")
private String name;
/**
* 区域编码
*/
@TableField(value = "UNITINDEXCODE")
private String unitIndexCode;
/**
* 国标编码
*/
@TableField(value = "GBINDEXCODE")
private String gbIndexCode;
/**
* 设备编码
*/
@TableField(value = "DEVICEINDEXCODE")
private String deviceIndexCode;
/**
* 纬度
*/
@TableField(value = "LATITUDE")
private String latitude;
/**
* 经度
*/
@TableField(value = "LONGITUDE")
private String longitude;
/**
* 高度
*/
@TableField(value = "ALTITUDE")
private String altitude;
/**
* 像素
*/
@TableField(value = "PIXEL")
private Integer pixel;
/**
* 相机类别
*/
@TableField(value = "CAMERATYPE")
private Integer cameraType;
/**
* 安装位置
*/
@TableField(value = "INSTALLPLACE")
private String installPlace;
/**
* 矩阵编号
*/
@TableField(value = "MATRIXCODE")
private String matrixCode;
/**
* 频道号
*/
@TableField(value = "CHANNUM")
private Integer chanNum;
/**
* 查看棚
*/
@TableField(value = "VIEWSHED")
private String viewShed;
/**
* 能力集
*/
@TableField(value = "CAPABILITYSET")
private String capabilitySet;
/**
* 智能套装
*/
@TableField(value = "INTELLIGENTSET")
private String intelligentSet;
/**
* 记录位置
*/
@TableField(value = "RECORDLOCATION")
private String recordLocation;
/**
* 云台控制
*/
@TableField(value = "PTZCONTROLLER")
private String ptzController;
/**
* 设备资源类型
*/
@TableField(value = "DEVICERESOURCETYPE")
private String deviceResourceType;
/**
* 信道类型
*/
@TableField(value = "CHANNELTYPE")
private String channelType;
/**
* 转换类型
*/
@TableField(value = "TRANSTYPE")
private Integer transType;
/**
* 更新时间
*/
@TableField(value = "UPDATETIME")
private String updateTime;
/**
* 创建时间
*/
@TableField(value = "CREATETIME")
private String createTime;
/**
* 状态
*/
@TableField(value = "STATUS")
private Integer status;
/**
* 相机类型名称
*/
@TableField(value = "CAMERATYPENAME")
private String cameraTypeName;
/**
* 能力集名称
*/
@TableField(value = "CAPABILITYSETNAME")
private String capabilitySetName;
/**
* 智能设置名称
*/
@TableField(value = "INTELLIGENTSETNAME")
private String intelligentSetName;
/**
* 记录位置名称
*/
@TableField(value = "RECORDLOCATIONNAME")
private String recordLocationName;
/**
* 云台控制名称
*/
@TableField(value = "PTZCONTROLLERNAME")
private String ptzControllerName;
/**
* 设备资源类型名称
*/
@TableField(value = "DEVICERESOURCETYPENAME")
private String deviceResourceTypeName;
/**
*
* 频道类型名称
*/
@TableField(value = "CHANNELTYPENAME")
private String channelTypeName;
/**
* 转换类型名称
*/
@TableField(value = "TRANSTYPENAME")
private String transTypeName;
/**
* 条约类型
*/
@TableField(value = "TREATYTYPE")
private String treatyType;
/**
* 条约类型名称
*/
@TableField(value = "TREATYTYPENAME")
private String treatyTypeName;
/**
* 状态名称
*/
@TableField(value = "STATUSNAME")
private String statusName;
}
VO类:
package com.byx.communitycontrol.common.vo;
import com.byx.communitycontrol.common.entity.baseinfo.PointInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = true)
public class PointInfoVo extends PointInfo implements Serializable {
/**
* 相机名称
*/
private String cameraName;
/**
* 区域名称
*/
private String qyName;
/**
* IP
*/
private String complexIp;
/**
* 上级IP
*/
private String parentIp;
}
mapper接口:
package com.byx.communitycontrol.gm.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.byx.communitycontrol.common.entity.baseinfo.PointInfo;
import com.byx.communitycontrol.common.vo.PointInfoVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface PointInfoMapper extends BaseMapper<PointInfo> {
//常规写法
@Select("SELECT\n" +
"\td.CAMERAINDEXCODE,\n" +
"\td.NAME,\n" +
"\td.UNITINDEXCODE,\n" +
"\td.GBINDEXCODE,\n" +
"\td.DEVICEINDEXCODE,\n" +
"\tqd.CAMERANAME,\n" +
"\tqx.NAME AS qyname,\n" +
"\td.STATUS,\n" +
"\td.STATUSNAME,\n" +
"\td.LATITUDE,\n" +
"\td.LONGITUDE,\n" +
"\td.ALTITUDE,\n" +
"\ti.COMPLEXIP,\n" +
"\ti.PARENTIP,\n" +
"\td.CREATETIME,\n" +
"\td.UPDATETIME \n" +
"FROM\n" +
"\tT_DWXX d\n" +
"\tLEFT JOIN T_DWXXIP i ON d.CAMERAINDEXCODE = i.CAMERAINDEXCODE\n" +
"\tLEFT JOIN T_QY_DW qd ON d.CAMERAINDEXCODE = qd.CAMERAINDEXCODE\n" +
"\tLEFT JOIN T_QYXX qx ON d.UNITINDEXCODE = qx.INDEXCODE \n" +
"${ew.customSqlSegment} " +
"ORDER BY\n" +
"\td.UPDATETIME DESC")
IPage<PointInfoVo> getPointInfoPageList(Page<?> page, @Param("ew") Wrapper wrapper);
//可返回一个List集合,之后再用page.setRecords()方法将集合set进去
@Select("SELECT\n" +
"\td.CAMERAINDEXCODE,\n" +
"\td.NAME,\n" +
"\td.UNITINDEXCODE,\n" +
"\td.GBINDEXCODE,\n" +
"\td.DEVICEINDEXCODE,\n" +
"\tqd.CAMERANAME,\n" +
"\tqx.NAME AS qyname,\n" +
"\td.STATUS,\n" +
"\td.STATUSNAME,\n" +
"\td.LATITUDE,\n" +
"\td.LONGITUDE,\n" +
"\td.ALTITUDE,\n" +
"\ti.COMPLEXIP,\n" +
"\ti.PARENTIP,\n" +
"\td.CREATETIME,\n" +
"\td.UPDATETIME \n" +
"FROM\n" +
"\tT_DWXX d\n" +
"\tLEFT JOIN T_DWXXIP i ON d.CAMERAINDEXCODE = i.CAMERAINDEXCODE\n" +
"\tLEFT JOIN T_QY_DW qd ON d.CAMERAINDEXCODE = qd.CAMERAINDEXCODE\n" +
"\tLEFT JOIN T_QYXX qx ON d.UNITINDEXCODE = qx.INDEXCODE \n" +
"${ew.customSqlSegment} " +
"ORDER BY\n" +
"\td.UPDATETIME DESC")
List<PointInfoVo> getPointInfoPageList(Page<?> page, @Param("ew") Wrapper wrapper);
//可用实体属性代替查询元素
@Select("SELECT\n" +
"\td.*,\n" +
"\tqd.cameraName,\n" +
"\tqx.name AS qyName,\n" +
"\ti.complexIp,\n" +
"\ti.parentIp \n" +
"FROM\n" +
"\tT_DWXX d\n" +
"\tLEFT JOIN T_DWXXIP i ON d.cameraIndexCode = i.cameraIndexCode\n" +
"\tLEFT JOIN T_QY_DW qd ON d.cameraIndexCode = qd.cameraIndexCode\n" +
"\tLEFT JOIN T_QYXX qx ON d.unitIndexCode = qx.indexCode \n" +
"${ew.customSqlSegment} " +
"ORDER BY\n" +
"\td.updateTime DESC")
IPage<PointInfoVo> getPointInfoPageList(Page<?> page, @Param("ew") Wrapper wrapper);
}
serviceImpl类:
package com.byx.communitycontrol.gm.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.byx.communitycontrol.common.entity.AppPage;
import com.byx.communitycontrol.common.entity.baseinfo.PointInfo;
import com.byx.communitycontrol.common.request.PointInfoPageReq;
import com.byx.communitycontrol.common.vo.PointInfoVo;
import com.byx.communitycontrol.context.helper.MyBatisPlusPageImpl;
import com.byx.communitycontrol.gm.mapper.PointInfoMapper;
import com.byx.communitycontrol.gm.service.IPointInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
@Service
public class PointInfoServiceImpl extends ServiceImpl<PointInfoMapper, PointInfo> implements IPointInfoService {
@Resource
private PointInfoMapper pointInfoMapper;
@Override
public AppPage<PointInfoVo> findListByPageCondition(PointInfoPageReq request) {
Page<PointInfoVo> page = new Page(request.getCurrentPage(), request.getPageSize());
//方法一:
QueryWrapper<PointInfoVo> queryWrapper = new QueryWrapper<>();
queryWrapper.like(StringUtils.hasText(request.getDwName()), "name", request.getDwName());
queryWrapper.like(StringUtils.hasText(request.getQyName()), "qyName", request.getQyName());
queryWrapper.eq(request.getStatus() != null, "status", request.getStatus());
List<PointInfoVo> pointInfoPageList = pointInfoMapper.getPointInfoPageList(page, queryWrapper);
Page<PointInfoVo> pointInfoVoPage = page.setRecords(pointInfoPageList);
//方法二:
QueryWrapper<PointInfoVo> eq = Wrappers.query(new PointInfoVo()).like(StringUtils.hasText(request.getDwName()),
"d.name",
request.getDwName()).like(StringUtils.hasText(request.getQyName()), "qx.name",
request.getQyName()).eq(request.getStatus() != null, "d.status", request.getStatus());
IPage<PointInfoVo> pointInfoPageList = pointInfoMapper.getPointInfoPageList(page, eq);
方法三:可将 Wrappers.query(new PointInfoVo()).like(...)... 换成 Wrappers.lambdaQuery(PointInfoVo.class).like(StringUtils.hasText(request.getDwName()),PointInfoVo::getName,
request.getDwName())...
return new MyBatisPlusPageImpl<>(pointInfoPageList);
}
}