修改基础信息页面的必填属性后,需要清空 device_info 表的 latest_reporting_time 属性。删除 device_data 中对应的数据

master
李一帆 2022-11-04 17:09:49 +08:00
parent 51a98cdf44
commit f871f315d5
6 changed files with 60 additions and 7 deletions

View File

@ -21,4 +21,6 @@ public interface DeviceDataMapper extends BaseMapper<DeviceData> {
* @return * @return
*/ */
IPage<DeviceData> page(@Param("page") IPage<SysUser> page, @Param("obj") FindDeviceDto findDto); IPage<DeviceData> page(@Param("page") IPage<SysUser> page, @Param("obj") FindDeviceDto findDto);
void clearByDeviceId(@Param("deviceId") String deviceId, @Param("channelNum") Integer channelNum);
} }

View File

@ -33,7 +33,7 @@ public interface IDeviceInfoService extends IService<DeviceInfo> {
List<DeviceInfo> list(String stationCode); List<DeviceInfo> list(String stationCode);
List<DeviceInfo> listAll(); List<DeviceInfo> listAll();
boolean updateByIdInternal(DeviceInfo entity);
/** /**
* *
* *

View File

@ -167,7 +167,7 @@ public class DeviceDataServiceImpl extends ServiceImpl<DeviceDataMapper, DeviceD
cnt += 1; cnt += 1;
di.setLatestReportingTime(dd.getTimestamp()); di.setLatestReportingTime(dd.getTimestamp());
iDeviceInfoService.updateById(di); iDeviceInfoService.updateByIdInternal(di);
changeDi = true; changeDi = true;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whdc.zhdbaqapi.constant.Constants; import com.whdc.zhdbaqapi.constant.Constants;
import com.whdc.zhdbaqapi.exception.MyException; import com.whdc.zhdbaqapi.exception.MyException;
import com.whdc.zhdbaqapi.mapper.DeviceDataMapper;
import com.whdc.zhdbaqapi.mapper.DeviceInfoMapper; import com.whdc.zhdbaqapi.mapper.DeviceInfoMapper;
import com.whdc.zhdbaqapi.model.dto.FindDeviceDto; import com.whdc.zhdbaqapi.model.dto.FindDeviceDto;
import com.whdc.zhdbaqapi.model.entity.DeviceInfo; import com.whdc.zhdbaqapi.model.entity.DeviceInfo;
@ -22,6 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
/** /**
@ -32,6 +35,18 @@ import java.util.*;
public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements IDeviceInfoService { public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements IDeviceInfoService {
@Autowired @Autowired
private RedisTemplate<String, String> redisTemplate; private RedisTemplate<String, String> redisTemplate;
@Autowired
private DeviceDataMapper deviceDataMapper;
private static long defaultTimeStamp;
static {
try {
defaultTimeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2022-07-01 00:00:00").getTime();
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
@Override @Override
public DeviceInfo get(Integer id) { public DeviceInfo get(Integer id) {
@ -55,10 +70,43 @@ public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceI
@CacheEvict(Constants.CACHE_NAME) @CacheEvict(Constants.CACHE_NAME)
public boolean updateById(DeviceInfo entity) { public boolean updateById(DeviceInfo entity) {
DeviceInfo old = baseMapper.checkValidStationCode(entity.getStationCode()); DeviceInfo old = baseMapper.checkValidStationCode(entity.getStationCode());
if (old == null) {
throw new MyException("stationCode=" + entity.getStationCode() + " 没有找到");
}
if (old != null && !old.getId().equals(entity.getId())) { if (old != null && !old.getId().equals(entity.getId())) {
throw new MyException("stationCode=" + entity.getStationCode() + " 已被其他有效数据使用,不能恢复"); throw new MyException("stationCode=" + entity.getStationCode() + " 已被其他有效数据使用,不能恢复");
} }
entity.setModificationTime(new Date()); entity.setModificationTime(new Date());
System.out.println("==============================");
System.out.println(old.getChannelNum());
System.out.println(entity.getChannelNum());
System.out.println("==============================");
if (
!old.getChannelNum().equals(entity.getChannelNum())
|| !old.getStationCode().equals(entity.getStationCode())
|| !old.getInitialReading().equals(entity.getInitialReading())
|| !old.getStartTemperature().equals(entity.getStartTemperature())
|| !old.getCalibrationCoefficient().equals(entity.getCalibrationCoefficient())
|| !old.getTemperatureK().equals(entity.getTemperatureK())
|| !old.getDeviceId().equals(entity.getDeviceId())
|| !old.getDistFromOsmosisMeterToBottom().equals(entity.getDistFromOsmosisMeterToBottom())
|| !old.getEmbeddingElevation().equals(entity.getEmbeddingElevation())
) {
entity.setLatestReportingTime(new Date(defaultTimeStamp));
deviceDataMapper.clearByDeviceId(entity.getDeviceId(), entity.getChannelNum());
}
return super.updateById(entity);
}
@Override
@CacheEvict(Constants.CACHE_NAME)
public boolean updateByIdInternal(DeviceInfo entity) {
DeviceInfo old = baseMapper.checkValidStationCode(entity.getStationCode());
if (old != null && !old.getId().equals(entity.getId())) {
throw new MyException("stationCode=" + entity.getStationCode() + " 已被其他有效数据使用,不能恢复");
}
entity.setModificationTime(new Date());
return super.updateById(entity); return super.updateById(entity);
} }

View File

@ -22,4 +22,7 @@
ORDER BY D.TIMESTAMP DESC ORDER BY D.TIMESTAMP DESC
</select> </select>
<delete id="clearByDeviceId">
delete from dam_safe.device_data where device_id=#{deviceId} and channel_num=#{channelNum}
</delete>
</mapper> </mapper>

View File

@ -57,7 +57,7 @@
</select> </select>
<select id="checkValidStationCode" resultType="com.whdc.zhdbaqapi.model.entity.DeviceInfo"> <select id="checkValidStationCode" resultType="com.whdc.zhdbaqapi.model.entity.DeviceInfo">
SELECT ID, STATION_CODE FROM DEVICE_INFO SELECT * FROM DEVICE_INFO
WHERE DEL = 0 WHERE DEL = 0
AND STATION_CODE = #{stationCode} AND STATION_CODE = #{stationCode}
LIMIT 1 LIMIT 1