修改基础信息页面的必填属性后,需要清空 device_info 表的 latest_reporting_time 属性。删除 device_data 中对应的数据
parent
51a98cdf44
commit
f871f315d5
|
|
@ -21,4 +21,6 @@ public interface DeviceDataMapper extends BaseMapper<DeviceData> {
|
|||
* @return
|
||||
*/
|
||||
IPage<DeviceData> page(@Param("page") IPage<SysUser> page, @Param("obj") FindDeviceDto findDto);
|
||||
|
||||
void clearByDeviceId(@Param("deviceId") String deviceId, @Param("channelNum") Integer channelNum);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public interface IDeviceInfoService extends IService<DeviceInfo> {
|
|||
List<DeviceInfo> list(String stationCode);
|
||||
|
||||
List<DeviceInfo> listAll();
|
||||
|
||||
boolean updateByIdInternal(DeviceInfo entity);
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ public class DeviceDataServiceImpl extends ServiceImpl<DeviceDataMapper, DeviceD
|
|||
cnt += 1;
|
||||
|
||||
di.setLatestReportingTime(dd.getTimestamp());
|
||||
iDeviceInfoService.updateById(di);
|
||||
iDeviceInfoService.updateByIdInternal(di);
|
||||
changeDi = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.whdc.zhdbaqapi.constant.Constants;
|
||||
import com.whdc.zhdbaqapi.exception.MyException;
|
||||
import com.whdc.zhdbaqapi.mapper.DeviceDataMapper;
|
||||
import com.whdc.zhdbaqapi.mapper.DeviceInfoMapper;
|
||||
import com.whdc.zhdbaqapi.model.dto.FindDeviceDto;
|
||||
import com.whdc.zhdbaqapi.model.entity.DeviceInfo;
|
||||
|
|
@ -22,6 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
|
@ -32,6 +35,18 @@ import java.util.*;
|
|||
public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements IDeviceInfoService {
|
||||
@Autowired
|
||||
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
|
||||
public DeviceInfo get(Integer id) {
|
||||
|
|
@ -55,10 +70,43 @@ public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|||
@CacheEvict(Constants.CACHE_NAME)
|
||||
public boolean updateById(DeviceInfo entity) {
|
||||
DeviceInfo old = baseMapper.checkValidStationCode(entity.getStationCode());
|
||||
if (old == null) {
|
||||
throw new MyException("stationCode=" + entity.getStationCode() + " 没有找到");
|
||||
}
|
||||
if (old != null && !old.getId().equals(entity.getId())) {
|
||||
throw new MyException("stationCode=" + entity.getStationCode() + " 已被其他有效数据使用,不能恢复");
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -116,10 +164,10 @@ public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|||
return new DeviceInfoImpVo().setLoad(0).setSuccess(0).setFail(0).setMsg("没有读取有有效数据");
|
||||
}
|
||||
|
||||
List<DeviceInfo> err = new ArrayList<>();
|
||||
List<DeviceInfo> impList = new ArrayList<>();
|
||||
Set<String> scs = new HashSet<>();
|
||||
Map<String, DeviceInfo> chkMap = new HashMap<>();
|
||||
List<DeviceInfo> err = new ArrayList<>();
|
||||
List<DeviceInfo> impList = new ArrayList<>();
|
||||
Set<String> scs = new HashSet<>();
|
||||
Map<String, DeviceInfo> chkMap = new HashMap<>();
|
||||
|
||||
for (DeviceInfo di : list) {
|
||||
if (StringUtils.isBlank(di.getStationCode())) {
|
||||
|
|
|
|||
|
|
@ -22,4 +22,7 @@
|
|||
ORDER BY D.TIMESTAMP DESC
|
||||
</select>
|
||||
|
||||
<delete id="clearByDeviceId">
|
||||
delete from dam_safe.device_data where device_id=#{deviceId} and channel_num=#{channelNum}
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
</select>
|
||||
|
||||
<select id="checkValidStationCode" resultType="com.whdc.zhdbaqapi.model.entity.DeviceInfo">
|
||||
SELECT ID, STATION_CODE FROM DEVICE_INFO
|
||||
SELECT * FROM DEVICE_INFO
|
||||
WHERE DEL = 0
|
||||
AND STATION_CODE = #{stationCode}
|
||||
LIMIT 1
|
||||
|
|
|
|||
Loading…
Reference in New Issue