Browse Source

上传设备查询SQL优化

develop
zhaoxianglong 10 months ago
parent
commit
34b15e7f76
  1. 6
      zc-business/src/main/java/com/zc/business/domain/DcDevice.java
  2. 44
      zc-business/src/main/java/com/zc/business/entity/EntityDcDevice.java
  3. 4
      zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java
  4. 7
      zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java
  5. 35
      zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java
  6. 89
      zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml

6
zc-business/src/main/java/com/zc/business/domain/DcDevice.java

@ -1,5 +1,6 @@
package com.zc.business.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -50,5 +51,8 @@ public class DcDevice {
private Date createTime;
@ApiModelProperty("修改时间")
private Date updateTime;
@TableField(exist = false)
private String longitude;
@TableField(exist = false)
private String latitude;
}

44
zc-business/src/main/java/com/zc/business/entity/EntityDcDevice.java

@ -1,44 +0,0 @@
package com.zc.business.entity;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcStakeMark;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel(value = "EntityDcDevice", description = "设备返回参数")
public class EntityDcDevice extends DcDevice {
private String longitude;
private String latitude;
public EntityDcDevice EstablishEntityDcDevice(DcDevice device, DcStakeMark dcStakeMark) {
EntityDcDevice entityDcDevice = new EntityDcDevice();
entityDcDevice.setId(device.getId());
entityDcDevice.setIotDeviceId(device.getIotDeviceId());
entityDcDevice.setGroupId(device.getGroupId());
entityDcDevice.setProductId(device.getProductId());
entityDcDevice.setStakeMarkId(device.getStakeMarkId());
entityDcDevice.setDirection(device.getDirection());
entityDcDevice.setDeviceCode(device.getDeviceCode());
entityDcDevice.setDeviceName(device.getDeviceName());
entityDcDevice.setDeviceType(device.getDeviceType());
entityDcDevice.setInstallationDate(device.getInstallationDate());
entityDcDevice.setProductionDate(device.getProductionDate());
entityDcDevice.setDurableYears(device.getDurableYears());
entityDcDevice.setInstallationSite(device.getInstallationSite());
entityDcDevice.setUseState(device.getUseState());
entityDcDevice.setOtherConfig(device.getOtherConfig());
entityDcDevice.setRemark(device.getRemark());
entityDcDevice.setCreateTime(device.getCreateTime());
entityDcDevice.setUpdateTime(device.getUpdateTime());
if (dcStakeMark != null) {
entityDcDevice.setLongitude(dcStakeMark.getLongitude());
entityDcDevice.setLatitude(dcStakeMark.getLatitude());
}
return entityDcDevice;
}
}

4
zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zc.business.domain.DcDevice;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 设备Mapper接口
*
@ -11,4 +13,6 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface DcDeviceMapper extends BaseMapper<DcDevice> {
List<DcDevice> selectDcDeviceList(DcDevice dcDevice);
}

7
zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java

@ -4,7 +4,6 @@ package com.zc.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcStakeMark;
import com.zc.business.entity.EntityDcDevice;
import java.util.List;
@ -45,7 +44,7 @@ public interface IDcDeviceService extends IService<DcDevice> {
* @param dcDevice 参数
* @return 结果
*/
List<EntityDcDevice> pageDevice(DcDevice dcDevice);
List<DcDevice> pageDevice(DcDevice dcDevice);
/**
* 获取设备列表
@ -53,7 +52,7 @@ public interface IDcDeviceService extends IService<DcDevice> {
* @param dcDevice 参数
* @return 结果
*/
List<EntityDcDevice> listDevice(DcDevice dcDevice);
List<DcDevice> listDevice(DcDevice dcDevice);
/**
* 批量修改设备
@ -70,7 +69,7 @@ public interface IDcDeviceService extends IService<DcDevice> {
* @param id 设备ID
* @return 设备信息
*/
EntityDcDevice getDevice(String id);
DcDevice getDevice(String id);
DcStakeMark exampleQueryTheAssociatedPileNumber(DcDevice dcDevice);
}

35
zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java

@ -8,7 +8,6 @@ import com.ruoyi.common.utils.PageUtils;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcProduct;
import com.zc.business.domain.DcStakeMark;
import com.zc.business.entity.EntityDcDevice;
import com.zc.business.mapper.DcDeviceMapper;
import com.zc.business.service.IDcDeviceService;
import com.zc.business.service.IDcProductService;
@ -17,7 +16,6 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@ -34,6 +32,9 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
private IDcProductService dcProdurtService;
@Resource
private IDcStakeMarkService dcStakeMarkService;
@Resource
private DcDeviceMapper dcDeviceMapper;
public LambdaQueryWrapper<DcDevice> deviceQueryWrapper(DcDevice dcDevice) {
@ -226,18 +227,10 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
* @return 分页查询结果
*/
@Override
public List<EntityDcDevice> pageDevice(DcDevice dcDevice) {
public List<DcDevice> pageDevice(DcDevice dcDevice) {
// 分页
PageUtils.startPage();
List<DcDevice> list = list(deviceQueryWrapper(dcDevice));
ArrayList<EntityDcDevice> entityDcDevices = new ArrayList<>();
for (DcDevice device : list) {
DcStakeMark dcStakeMark = exampleQueryTheAssociatedPileNumber(device);
EntityDcDevice entityDcDevice = new EntityDcDevice();
EntityDcDevice entityDcDevice1 = entityDcDevice.EstablishEntityDcDevice(device, dcStakeMark);
entityDcDevices.add(entityDcDevice1);
}
return entityDcDevices;
return dcDeviceMapper.selectDcDeviceList(dcDevice);
}
/**
@ -247,16 +240,8 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
* @return 查询结果
*/
@Override
public List<EntityDcDevice> listDevice(DcDevice dcDevice) {
List<DcDevice> list = list(deviceQueryWrapper(dcDevice));
ArrayList<EntityDcDevice> entityDcDevices = new ArrayList<>();
for (DcDevice device : list) {
DcStakeMark dcStakeMark = exampleQueryTheAssociatedPileNumber(device);
EntityDcDevice entityDcDevice = new EntityDcDevice();
EntityDcDevice entityDcDevice1 = entityDcDevice.EstablishEntityDcDevice(device, dcStakeMark);
entityDcDevices.add(entityDcDevice1);
}
return entityDcDevices;
public List<DcDevice> listDevice(DcDevice dcDevice) {
return dcDeviceMapper.selectDcDeviceList(dcDevice);
}
/**
@ -282,16 +267,14 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
* @return 查询结果
*/
@Override
public EntityDcDevice getDevice(String id) {
public DcDevice getDevice(String id) {
// 检查设备id是否重复
DcDevice device = getById(id);
if (Objects.isNull(device)) {
throw new ServiceException("设备ID[" + id + "]不存在", HttpStatus.BAD_REQUEST);
}
DcStakeMark dcStakeMark = exampleQueryTheAssociatedPileNumber(device);
EntityDcDevice entityDcDevice = new EntityDcDevice();
return entityDcDevice.EstablishEntityDcDevice(device, dcStakeMark);
return device;
}
@Override

89
zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zc.business.mapper.DcDeviceMapper">
<resultMap type="DcDevice" id="DcDevice">
<result property="id" column="id"/>
<result property="iotDeviceId" column="iot_device_id"/>
<result property="groupId" column="group_id"/>
<result property="productId" column="product_id"/>
<result property="stakeMarkId" column="stake_mark_id"/>
<result property="direction" column="direction"/>
<result property="deviceName" column="device_name"/>
<result property="deviceCode" column="device_code"/>
<result property="deviceType" column="device_type"/>
<result property="installationDate" column="installation_Date"/>
<result property="productionDate" column="production_date"/>
<result property="durableYears" column="durable_years"/>
<result property="installationSite" column="installation_site"/>
<result property="useState" column="use_state"/>
<result property="otherConfig" column="other_config"/>
<result property="remark" column="remark"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="longitude" column="longitude"/>
<result property="latitude" column="latitude"/>
</resultMap>
<resultMap id="dcStakeMarkResult" type="dcStakeMark">
<result property="longitude" column="longitude"/>
<result property="latitude" column="latitude"/>
</resultMap>
<sql id="selectDcDeviceVo">
select id,
iot_device_id,
group_id,
product_id,
stake_mark_id,
direction,
device_name,
device_code,
device_type,
installation_Date,
production_date,
durable_years,
installation_site,
use_state,
other_config,
remark,
create_time,
update_time
from dc_device
</sql>
<select id="selectDcDeviceList" parameterType="dcDevice" resultMap="DcDevice">
select t1.id, t1.iot_device_id, t1.group_id, t1.product_id, t1.stake_mark_id, t1.direction, t1.device_name, t1.device_code, t1.device_type,
t1.installation_Date,t1.production_date,t1.durable_years,t1.installation_site,t1.use_state,t1.other_config,t1.remark,t1.create_time,t1.update_time,
t2.longitude,t2.latitude
from dc_device t1
left join dc_stake_mark t2 on t1.stake_mark_id = t2.id and t1.direction = t2.direction
<where>
<if test="id != null and id != ''">and t1.id = #{id}</if>
<if test="iotDeviceId != null and iotDeviceId != ''">and t1.iot_device_id = #{iotDeviceId}</if>
<if test="groupId != null and groupId != ''">and t1.group_id = #{groupId}</if>
<if test="productId != null and productId != ''">and t1.product_id = #{productId}</if>
<if test="stakeMarkId != null and stakeMarkId != ''">and t1.stake_mark_id = #{stakeMarkId}</if>
<if test="direction != null and direction != ''">and t1.direction = #{direction}</if>
<if test="deviceName != null and deviceName != ''">and t1.device_name like concat('%', #{deviceName}, '%')</if>
<if test="deviceCode != null and deviceCode != ''">and t1.device_code = #{deviceCode}</if>
<if test="deviceType != null and deviceType != ''">and t1.device_type = #{deviceType}</if>
<if test="installationDate != null and installationDate != ''">and t1.installation_Date = #{installationDate}</if>
<if test="productionDate != null and productionDate != ''">and t1.production_date = #{productionDate}</if>
<if test="durableYears != null and durableYears != ''">and t1.durable_years = #{durableYears}</if>
<if test="installationSite != null and installationSite != ''">and t1.installation_site = #{installationSite}</if>
<if test="useState != null and useState != ''">and t1.use_state = #{useState}</if>
<if test="otherConfig != null and otherConfig != ''">and t1.other_config = #{otherConfig}</if>
<if test="remark != null and remark != ''">and t1.remark = #{remark}</if>
<if test="createTime != null and createTime != ''">and t1.create_time = #{createTime}</if>
<if test="updateTime != null and updateTime != ''">and t1.update_time = #{updateTime}</if>
</where>
</select>
</mapper>
Loading…
Cancel
Save