决策信息绑定高峰时间段配置

This commit is contained in:
tiger_zhou 2023-09-18 16:22:11 +08:00
parent 90caf3cd49
commit fa7eb30abc
25 changed files with 582 additions and 136 deletions

View File

@ -32,41 +32,6 @@ public class AlertDetailFactory {
}
public NccAlertInfo getAlertDetail2(AlertType alertType, int lineId) {
switch (alertType) {
case BLUE_DISPLAY -> {
}
case SWITCH_LOST -> {
}
case SWITCH_LOST_MOST -> {
}
case AXLE_LED_RED -> {
}
case AXLE_LED_RED_MOST -> {
}
case AXLE_LED_ORANGE -> {
}
case AXLE_LED_ORANGE_MOST -> {
}
case PLATFORM_DOOR_CANNOT_OPEN -> {
}
case PLATFORM_DOOR_CANNOT_CLOSE -> {
}
}
return null;
}
public NccAlertInfo getAlertDetail(LocalDateTime alertTime, AlertType alertType, int lineId,
boolean mock, MessageOrBuilder messageOrBuilder) {
String alertObject;

View File

@ -111,7 +111,7 @@ public class NccAlertInfo implements AlertInfo {
return "III";
}
case BLUE_DISPLAY, PLATFORM_DOOR_CANNOT_CLOSE, PLATFORM_DOOR_CANNOT_OPEN,
PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL, TRAIN_DELAY_10, SWITCH_LOST,
PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL, TRAIN_DELAY_10, SWITCH_LOST, SWITCH_FW_LOST, SWITCH_All_LOST, SWITCH_DW_LOST,
SWITCH_LOST_MOST, AXLE_LED_RED, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST, TRAIN_EB_ATP, ALL_LINE_BLUE_DISPLAY -> {
return "I";
}

View File

@ -56,12 +56,6 @@ public class AlertTipController {
alertTipService.save(saveDTO);
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "插入或更新报警提示信息")
@PostMapping("/saveOrUpdate")
public void saveOrUpdate(@RequestBody @Validated AlertTipSaveDTO saveDTO) {
alertTipService.saveOrUpdate(saveDTO);
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "根据id查询数据")
@ -75,22 +69,16 @@ public class AlertTipController {
@ApiResponse(description = "报警提示信息分页")
@GetMapping("/page")
public IPage<AlertTipInfoDto> pageAlertTips(AlertTipQueryDTO alertTipQueryDTO) {
return this.alertTipRepository.leftAreaPage(alertTipQueryDTO);
return this.alertTipService.page(alertTipQueryDTO);
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "根据id更新数据")
@PutMapping("/id")
public void updateById(@RequestBody AlertTip alertTip) {
alertTipRepository.updateById(alertTip);
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "根据id删除数据")
@ApiResponse(description = "是否确实删除掉了一条数据")
@DeleteMapping("/id/{id}")
public boolean deleteById(@PathVariable int id) {
return alertTipRepository.removeById(id);
return this.alertTipRepository.removeById(id);
}
@SecurityRequirement(name = "jwt")

View File

@ -0,0 +1,55 @@
package club.joylink.xiannccda.controller;
import club.joylink.xiannccda.dto.alertTip.AlertTipTimeQueryDTO;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import club.joylink.xiannccda.repository.impl.AlertTipTimeConfigRepository;
import club.joylink.xiannccda.service.TipTimeConfigService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 前端控制器
* </p>
*
* @author walker-sheng
* @since 2023-09-18
*/
@RestController
@RequestMapping("/alert/tip/time")
public class AlertTipTimeConfigController {
private final TipTimeConfigService timeConfigService;
private final AlertTipTimeConfigRepository configRepository;
public AlertTipTimeConfigController(TipTimeConfigService timeConfigService, AlertTipTimeConfigRepository configRepository) {
this.timeConfigService = timeConfigService;
this.configRepository = configRepository;
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "保存修改")
@PostMapping("")
public void save(@RequestBody AlertTipTimeConfig dto) {
this.timeConfigService.saveOrUpdate(dto);
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "保存修改")
@PostMapping("page")
public IPage<AlertTipTimeConfig> page(AlertTipTimeQueryDTO dto) {
return this.configRepository.page(dto);
}
/* @SecurityRequirement(name = "jwt")
@Operation(summary = "保存修改")
@DeleteMapping("/{id}")
public void remove(@PathVariable("id") Long id) {
}*/
}

View File

@ -36,11 +36,9 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/api/config/device/area")
public class DeviceAreaConfigController {
private DeviceAreaConfigRepository deviceAreaConfigRepository;
private DeviceAreaConfigService areaConfigService;
public DeviceAreaConfigController(DeviceAreaConfigRepository deviceAreaConfigRepository, DeviceAreaConfigService areaConfigService) {
this.deviceAreaConfigRepository = deviceAreaConfigRepository;
public DeviceAreaConfigController(DeviceAreaConfigService areaConfigService) {
this.areaConfigService = areaConfigService;
}

View File

@ -4,6 +4,10 @@ import club.joylink.xiannccda.alert.AlertTipTimeType;
import club.joylink.xiannccda.dto.protos.AlertConstProto;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -12,46 +16,32 @@ import org.apache.commons.lang3.StringUtils;
@NoArgsConstructor
@Data
public class AlertTipInfoDto {
public AlertTipInfoDto(AlertTip at, String areaConfigName) {
this.id = at.getId();
this.alertType = at.getAlertType();
this.timeType = at.getTimeType();
this.areaConfigId = at.getAreaConfigId();
this.areaConfigName = areaConfigName;
this.drivingInfo = at.getDrivingInfo();
this.submissionInfo = at.getSubmissionInfo();
}
@Getter
@Setter
private Integer id;
private String alertType;
private String timeType;
@Getter
@Setter
private Long areaConfigId;
@Getter
@Setter
private String areaConfigName;
/**
* 行车方面提示信息
*/
@Getter
@Setter
private String drivingInfo;
/**
* 信息报送方面提示信息
*/
@Getter
@Setter
private String submissionInfo;
@JSONField(deserialize = false)
private String tipTimeRef;
private List<AlertTipTimeConfig> timeConfigList;
public AlertConstProto.AlertType getAlertType() {
if (StringUtils.isNotEmpty(this.alertType)) {
@ -60,10 +50,4 @@ public class AlertTipInfoDto {
return null;
}
public AlertTipTimeType getTimeType() {
if (StringUtils.isNotEmpty(this.timeType)) {
return AlertTipTimeType.valueOf(this.timeType);
}
return null;
}
}

View File

@ -4,11 +4,13 @@ import club.joylink.xiannccda.alert.AlertTipTimeType;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertLocation;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.Data;
@Data
public class AlertTipSaveDTO {
private Integer id;
@NotNull(message = "报警类型不能为空")
private AlertType alertType;
@ -25,4 +27,5 @@ public class AlertTipSaveDTO {
* 信息报送方面提示信息
*/
private String submissionInfo;
private List<Long> tipTimeIds;
}

View File

@ -0,0 +1,15 @@
package club.joylink.xiannccda.dto.alertTip;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class AlertTipTimeQueryDTO extends PageDTO<AlertTipTimeConfig> {
}

View File

@ -586,6 +586,164 @@ public final class AlertConstProto {
// @@protoc_insertion_point(enum_scope:alert.AlertType)
}
/**
* Protobuf enum {@code alert.TipTimeConfig}
*/
public enum TipTimeConfig
implements com.google.protobuf.ProtocolMessageEnum {
/**
* <pre>
*假期早高峰
* </pre>
*
* <code>HOLIDAYS_MORN_PEAK = 0;</code>
*/
HOLIDAYS_MORN_PEAK(0),
/**
* <pre>
*假期晚高峰
* </pre>
*
* <code>HOLIDAYS_EVENING_PEAK = 1;</code>
*/
HOLIDAYS_EVENING_PEAK(1),
/**
* <pre>
*早高峰
* </pre>
*
* <code>MORN_PEAK = 2;</code>
*/
MORN_PEAK(2),
/**
* <pre>
*晚高峰
* </pre>
*
* <code>EVENING_PEARK = 3;</code>
*/
EVENING_PEARK(3),
UNRECOGNIZED(-1),
;
/**
* <pre>
*假期早高峰
* </pre>
*
* <code>HOLIDAYS_MORN_PEAK = 0;</code>
*/
public static final int HOLIDAYS_MORN_PEAK_VALUE = 0;
/**
* <pre>
*假期晚高峰
* </pre>
*
* <code>HOLIDAYS_EVENING_PEAK = 1;</code>
*/
public static final int HOLIDAYS_EVENING_PEAK_VALUE = 1;
/**
* <pre>
*早高峰
* </pre>
*
* <code>MORN_PEAK = 2;</code>
*/
public static final int MORN_PEAK_VALUE = 2;
/**
* <pre>
*晚高峰
* </pre>
*
* <code>EVENING_PEARK = 3;</code>
*/
public static final int EVENING_PEARK_VALUE = 3;
public final int getNumber() {
if (this == UNRECOGNIZED) {
throw new java.lang.IllegalArgumentException(
"Can't get the number of an unknown enum value.");
}
return value;
}
/**
* @param value The numeric wire value of the corresponding enum entry.
* @return The enum associated with the given numeric wire value.
* @deprecated Use {@link #forNumber(int)} instead.
*/
@java.lang.Deprecated
public static TipTimeConfig valueOf(int value) {
return forNumber(value);
}
/**
* @param value The numeric wire value of the corresponding enum entry.
* @return The enum associated with the given numeric wire value.
*/
public static TipTimeConfig forNumber(int value) {
switch (value) {
case 0: return HOLIDAYS_MORN_PEAK;
case 1: return HOLIDAYS_EVENING_PEAK;
case 2: return MORN_PEAK;
case 3: return EVENING_PEARK;
default: return null;
}
}
public static com.google.protobuf.Internal.EnumLiteMap<TipTimeConfig>
internalGetValueMap() {
return internalValueMap;
}
private static final com.google.protobuf.Internal.EnumLiteMap<
TipTimeConfig> internalValueMap =
new com.google.protobuf.Internal.EnumLiteMap<TipTimeConfig>() {
public TipTimeConfig findValueByNumber(int number) {
return TipTimeConfig.forNumber(number);
}
};
public final com.google.protobuf.Descriptors.EnumValueDescriptor
getValueDescriptor() {
if (this == UNRECOGNIZED) {
throw new java.lang.IllegalStateException(
"Can't get the descriptor of an unrecognized enum value.");
}
return getDescriptor().getValues().get(ordinal());
}
public final com.google.protobuf.Descriptors.EnumDescriptor
getDescriptorForType() {
return getDescriptor();
}
public static final com.google.protobuf.Descriptors.EnumDescriptor
getDescriptor() {
return club.joylink.xiannccda.dto.protos.AlertConstProto.getDescriptor().getEnumTypes().get(2);
}
private static final TipTimeConfig[] VALUES = values();
public static TipTimeConfig valueOf(
com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
if (desc.getType() != getDescriptor()) {
throw new java.lang.IllegalArgumentException(
"EnumValueDescriptor is not for this type.");
}
if (desc.getIndex() == -1) {
return UNRECOGNIZED;
}
return VALUES[desc.getIndex()];
}
private final int value;
private TipTimeConfig(int value) {
this.value = value;
}
// @@protoc_insertion_point(enum_scope:alert.TipTimeConfig)
}
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
@ -609,8 +767,11 @@ public final class AlertConstProto {
"D_MOST\020\016\022\023\n\017AXLE_LED_ORANGE\020\017\022\030\n\024AXLE_LE" +
"D_ORANGE_MOST\020\020\022\024\n\020SWITCH_LOST_MOST\020\021\022\020\n" +
"\014TRAIN_EB_ATP\020\022\022\031\n\025ALL_LINE_BLUE_DISPLAY" +
"\020\023B4\n!club.joylink.xiannccda.dto.protosB" +
"\017AlertConstProtob\006proto3"
"\020\023*d\n\rTipTimeConfig\022\026\n\022HOLIDAYS_MORN_PEA" +
"K\020\000\022\031\n\025HOLIDAYS_EVENING_PEAK\020\001\022\r\n\tMORN_P" +
"EAK\020\002\022\021\n\rEVENING_PEARK\020\003B4\n!club.joylink" +
".xiannccda.dto.protosB\017AlertConstProtob\006" +
"proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,

View File

@ -29,8 +29,8 @@ public class AlertTip {
@Schema(description = "故障类型")
private String alertType;
@Schema(description = "时间定义类型")
private String timeType;
/* @Schema(description = "时间定义类型")
private String timeType;*/
@Schema(description = "地点定义类型")
private Long areaConfigId;
@ -41,15 +41,18 @@ public class AlertTip {
@Schema(description = "信息报送方面提示信息")
private String submissionInfo;
@Schema(description = "关联高峰期id 以逗号隔开")
private String tipTimeRef;
public static final String ID = "id";
public static final String ALERT_TYPE = "alert_type";
public static final String TIME_TYPE = "time_type";
// public static final String TIME_TYPE = "time_type";
// public static final String LOCATION_TYPE = "location_type";
public static final String AREA_CONFIG_ID = "area_config_id";
public static final String DRIVING_INFO = "driving_info";
public static final String SUBMISSION_INFO = "submission_info";
public static final String TIP_TIME_REF = "tip_time_ref";
}

View File

@ -0,0 +1,55 @@
package club.joylink.xiannccda.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author walker-sheng
* @since 2023-09-18
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("alert_tip_time_config")
@Schema(name = "AlertTipTimeConfig", description = "$!{table.comment}")
public class AlertTipTimeConfig {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@Schema(description = "名称")
private String timeName;
@Schema(description = "开始小时数")
private Byte startHour;
@Schema(description = "结束小时数")
private Byte endHour;
@Schema(description = "时间配置类型")
private String timeType;
@Schema(description = "公休日是否高峰0=否1=是")
private Byte publicPeak;
public static final String ID = "id";
public static final String TIME_NAME = "time_name";
public static final String START_HOUR = "start_hour";
public static final String END_HOUR = "end_hour";
public static final String TIME_TYPE = "time_type";
public static final String PUBLIC_PEAK = "public_peak";
}

View File

@ -0,0 +1,18 @@
package club.joylink.xiannccda.mapper;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author walker-sheng
* @since 2023-09-18
*/
@Mapper
public interface AlertTipTimeConfigMapper extends BaseMapper<AlertTipTimeConfig> {
}

View File

@ -0,0 +1,20 @@
<?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="club.joylink.xiannccda.mapper.AlertTipTimeConfigMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="club.joylink.xiannccda.entity.AlertTipTimeConfig">
<id column="id" property="id" />
<result column="time_name" property="timeName" />
<result column="start_hour" property="startHour" />
<result column="end_hour" property="endHour" />
<result column="time_type" property="timeType" />
<result column="public_peak" property="publicPeak" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, time_name, start_hour, end_hour, time_type, public_peak
</sql>
</mapper>

View File

@ -19,7 +19,6 @@ import java.util.Map;
*/
public interface IAlertTipRepository extends IService<AlertTip> {
Page<AlertTip> page(AlertTipQueryDTO queryDTO);
Map<Long, String> findBindAreaConfigId(List<Long> areaConfigList);

View File

@ -0,0 +1,16 @@
package club.joylink.xiannccda.repository;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author walker-sheng
* @since 2023-09-18
*/
public interface IAlertTipTimeConfigRepository extends IService<AlertTipTimeConfig> {
}

View File

@ -13,6 +13,7 @@ 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.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
@ -30,23 +31,6 @@ import org.springframework.stereotype.Service;
@Service
public class AlertTipRepository extends ServiceImpl<AlertTipMapper, AlertTip> implements IAlertTipRepository {
@Override
public Page<AlertTip> page(AlertTipQueryDTO queryDTO) {
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
if (queryDTO.getAlertType() != null) {
queryWrapper.eq(AlertTip::getAlertType, queryDTO.getAlertType());
}
if (queryDTO.getTimeType() != null) {
queryWrapper.eq(AlertTip::getTimeType, queryDTO.getTimeType());
}
queryWrapper.eq(queryDTO.getAreaConfigId() != null, AlertTip::getAreaConfigId, queryDTO.getAreaConfigId());
/* if (queryDTO.getLocationType() != null) {
queryWrapper.eq(AlertTip::getLocationType, queryDTO.getLocationType().name());
}*/
queryWrapper.notIn(AlertTip::getAlertType, List.of(AlertType.SWITCH_LOST.name()));
return page(queryDTO, queryWrapper);
}
@Override
public Map<Long, String> findBindAreaConfigId(List<Long> areaConfigList) {
@ -67,6 +51,7 @@ public class AlertTipRepository extends ServiceImpl<AlertTipMapper, AlertTip> im
@Override
public IPage<AlertTipInfoDto> leftAreaPage(AlertTipQueryDTO queryDTO) {
return this.baseMapper.selectForPage(queryDTO);
}
}

View File

@ -0,0 +1,20 @@
package club.joylink.xiannccda.repository.impl;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import club.joylink.xiannccda.mapper.AlertTipTimeConfigMapper;
import club.joylink.xiannccda.repository.IAlertTipTimeConfigRepository;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author walker-sheng
* @since 2023-09-18
*/
@Service
public class AlertTipTimeConfigRepository extends ServiceImpl<AlertTipTimeConfigMapper, AlertTipTimeConfig> implements IAlertTipTimeConfigRepository {
}

View File

@ -1,46 +1,52 @@
package club.joylink.xiannccda.service;
import club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto;
import club.joylink.xiannccda.dto.alertTip.AlertTipQueryDTO;
import club.joylink.xiannccda.dto.alertTip.AlertTipSaveDTO;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import club.joylink.xiannccda.repository.IDeviceAreaConfigRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
@Service
public class AlertTipService {
private final IAlertTipRepository alertTipRepository;
private final TipTimeConfigService timeConfigService;
public AlertTipService(IAlertTipRepository alertTipRepository) {
public AlertTipService(IAlertTipRepository alertTipRepository, TipTimeConfigService timeConfigService) {
this.alertTipRepository = alertTipRepository;
this.timeConfigService = timeConfigService;
}
public void save(AlertTipSaveDTO saveDTO) {
AlertTip saveEntity = convertToEntity(saveDTO);
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
queryWrapper.eq(AlertTip::getAlertType, saveEntity.getAlertType())
.eq(AlertTip::getTimeType, saveEntity.getTimeType())
.eq(AlertTip::getAreaConfigId, saveEntity.getAreaConfigId())
;
.eq(AlertTip::getAreaConfigId, saveEntity.getAreaConfigId());
if (Objects.nonNull(saveEntity.getId()) && saveEntity.getId() > 0) {
long finder = this.alertTipRepository.count(Wrappers.lambdaQuery(AlertTip.class).ne(AlertTip::getId, saveEntity.getId()));
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(finder > 0L,
"未找到对应的数据");
queryWrapper.ne(AlertTip::getId, saveDTO.getId());
}
long count = alertTipRepository.count(queryWrapper);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(count == 0,
"相同报警类型、时间范围、地点范围的提示信息已存在");
alertTipRepository.save(saveEntity);
}
alertTipRepository.saveOrUpdate(saveEntity);
public void saveOrUpdate(AlertTipSaveDTO saveDTO) {
AlertTip saveEntity = convertToEntity(saveDTO);
LambdaUpdateWrapper<AlertTip> updateWrapper = Wrappers.lambdaUpdate(AlertTip.class);
updateWrapper.eq(AlertTip::getAlertType, saveEntity.getAlertType())
.eq(AlertTip::getTimeType, saveEntity.getTimeType())
.eq(AlertTip::getAreaConfigId, saveEntity.getAreaConfigId())
;
alertTipRepository.saveOrUpdate(saveEntity, updateWrapper);
}
@ -50,11 +56,6 @@ public class AlertTipService {
}
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class)
.eq(AlertTip::getAlertType, alertType);
/* if (alertLocation != null) {
queryWrapper.eq(AlertTip::getLocationType, alertLocation);
} else {
queryWrapper.isNull(AlertTip::getLocationType);
}*/
return Optional.ofNullable(alertTipRepository.getOne(queryWrapper, false));
}
@ -62,13 +63,25 @@ public class AlertTipService {
private AlertTip convertToEntity(AlertTipSaveDTO saveDTO) {
AlertTip entity = new AlertTip();
entity.setAlertType(saveDTO.getAlertType().name());
if (saveDTO.getTimeType() != null) {
entity.setTimeType(saveDTO.getTimeType().name());
}
entity.setAreaConfigId(saveDTO.getAreaConfigId());
entity.setDrivingInfo(saveDTO.getDrivingInfo());
entity.setSubmissionInfo(saveDTO.getSubmissionInfo());
entity.setId(saveDTO.getId());
entity.setTipTimeRef(Joiner.on(",").skipNulls().join(saveDTO.getTipTimeIds()));
return entity;
}
public IPage<AlertTipInfoDto> page(AlertTipQueryDTO queryDTO) {
IPage<AlertTipInfoDto> page = this.alertTipRepository.leftAreaPage(queryDTO);
for (AlertTipInfoDto record : page.getRecords()) {
if (StringUtils.isNotEmpty(record.getTipTimeRef())) {
List<String> tmpTimeId = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(record.getTipTimeRef());
List<Long> timeIdLong = tmpTimeId.stream().map(Long::parseLong).collect(Collectors.toList());
List<AlertTipTimeConfig> timeConfigList = this.timeConfigService.getCache(timeIdLong);
record.setTimeConfigList(timeConfigList);
}
}
return page;
}
}

View File

@ -0,0 +1,81 @@
package club.joylink.xiannccda.service;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import club.joylink.xiannccda.repository.IAlertTipTimeConfigRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.springframework.stereotype.Service;
@Service
public class TipTimeConfigService {
private final IAlertTipTimeConfigRepository iAlertTipTimeConfigRepository;
private final static Cache<Long, AlertTipTimeConfig> TIP_TIME_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(5 * 60, TimeUnit.SECONDS).build();
public AlertTipTimeConfig getCache(Long id) {
try {
return TIP_TIME_CONFIG_CACHE.get(id, () -> iAlertTipTimeConfigRepository.getById(id));
} catch (ExecutionException e) {
return null;
}
}
public List<AlertTipTimeConfig> getCache(List<Long> id) {
List<AlertTipTimeConfig> list = Lists.newArrayListWithCapacity(id.size());
for (Long aLong : id) {
AlertTipTimeConfig timeConfig = this.getCache(aLong);
if (Objects.nonNull(timeConfig)) {
list.add(timeConfig);
}
}
return list;
}
public List<AlertTipTimeConfig> getCache(Long... id) {
List<AlertTipTimeConfig> list = Lists.newArrayListWithCapacity(id.length);
for (Long aLong : id) {
AlertTipTimeConfig timeConfig = this.getCache(aLong);
if (Objects.nonNull(timeConfig)) {
list.add(timeConfig);
}
}
return list;
}
public TipTimeConfigService(IAlertTipTimeConfigRepository iAlertTipTimeConfigRepository) {
this.iAlertTipTimeConfigRepository = iAlertTipTimeConfigRepository;
}
public void saveOrUpdate(AlertTipTimeConfig timeConfig) {
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(StringUtils.isNotEmpty(timeConfig.getTimeName()), "高峰期名称不能为空");
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(StringUtils.isNotEmpty(timeConfig.getTimeType()), "高峰期类型不能为空");
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(timeConfig.getStartHour()), "高峰期开始时间不能为空");
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(timeConfig.getEndHour()), "高峰期结束不能为空");
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(timeConfig.getStartHour() <= timeConfig.getEndHour(), "高峰期结束时间不能大于开始时间");
LambdaQueryWrapper<AlertTipTimeConfig> queryWrapper = Wrappers.lambdaQuery(AlertTipTimeConfig.class);
queryWrapper.eq(AlertTipTimeConfig::getTimeType, timeConfig.getTimeType());
if (Objects.nonNull(timeConfig.getId()) && timeConfig.getId() > 0L) {
long isExist = this.iAlertTipTimeConfigRepository.count(Wrappers.lambdaQuery(AlertTipTimeConfig.class).eq(AlertTipTimeConfig::getId, timeConfig.getId()));
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isExist >= 1L, "没找到对应的数据");
queryWrapper.ne(AlertTipTimeConfig::getId, timeConfig.getId());
}
long counter = this.iAlertTipTimeConfigRepository.count(queryWrapper);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(counter == 0L, "重复的高峰期时间类型");
iAlertTipTimeConfigRepository.saveOrUpdate(timeConfig);
TIP_TIME_CONFIG_CACHE.invalidateAll();
}
}

View File

@ -43,7 +43,6 @@ public class DeviceAreaConfigService {
@Autowired
private IAlertTipRepository iAlertTipRepository;
// private final static Cache<Integer, Map<AlertDeviceType, List<DeviceAreaConfig>>> AREA_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(5 * 60, TimeUnit.SECONDS).build();
private final static Cache<Integer, Map<AlertDeviceType, List<AreaConfigVO>>> AREA_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(5 * 60, TimeUnit.SECONDS).build();
public List<AreaConfigVO> getCache(int lineId, AlertDeviceType dt) {

View File

@ -3,7 +3,7 @@
<mapper namespace="club.joylink.xiannccda.mapper.AlertTipMapper">
<select id="selectForPage" resultType="club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto">
select A.*, B.area_name as areaConfigName
select A.*, B.area_name as areaConfigName,A.tip_time_ref
from alert_tip A left join device_area_config B on A.area_config_id = B.id
where 1 = 1
<if test="tipQuery.alertType != null and tipQuery.alertType != ''">

View File

@ -17,16 +17,19 @@ import org.apache.ibatis.annotations.Mapper;
public class MybatisPlusGenerator {
public static final DataSourceConfig.Builder DataSourceConfigBuilder =
// new DataSourceConfig.Builder(
// "jdbc:mysql://192.168.3.233:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true",
// "root", "joylink0503");
new DataSourceConfig.Builder(
"jdbc:mysql://192.168.3.233:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true",
"root", "joylink0503");
"jdbc:mysql://localhost:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true",
"root", "root");
/**
* 生成剔除的表
*/
private static final List<String> includeTableList = new ArrayList<>();
static {
includeTableList.add("ncc_mock_data");
includeTableList.add("atip_time_ref");
}
public static void main(String[] args) {

View File

@ -20,14 +20,14 @@ import org.springframework.boot.test.context.SpringBootTest;
public class AlertTipServiceTest {
@Autowired
private IAlertTipRepository alertTipRepository;
private AlertTipService alertTipService;
@Test
public void page() {
AlertTipQueryDTO dto = new AlertTipQueryDTO();
dto.setAlertType(AlertType.BLUE_DISPLAY.name());
IPage<AlertTipInfoDto> page = this.alertTipRepository.leftAreaPage(dto);
IPage<AlertTipInfoDto> page = this.alertTipService.page(dto);
System.out.println(JSON.toJSONString(page, Feature.PrettyFormat));
}

View File

@ -0,0 +1,65 @@
package club.joylink.xiannccda.service;
import club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto;
import club.joylink.xiannccda.dto.alertTip.AlertTipQueryDTO;
import club.joylink.xiannccda.dto.alertTip.AlertTipSaveDTO;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.AlertConstProto.TipTimeConfig;
import club.joylink.xiannccda.dto.record.AlertRecordReportDTO;
import club.joylink.xiannccda.dto.record.AlertRecordReportResponseDTO;
import club.joylink.xiannccda.entity.AlertTipTimeConfig;
import club.joylink.xiannccda.repository.IAlertRecordRepository;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter.Feature;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class AlertTipTimeConfigServiceTest {
@Autowired
private TipTimeConfigService timeConfigService;
@Autowired
private AlertTipService alertTipService;
@Test
public void save() {
AlertTipTimeConfig timeConfig = new AlertTipTimeConfig();
timeConfig.setTimeName("123");
timeConfig.setTimeType(TipTimeConfig.EVENING_PEARK.name());
timeConfig.setStartHour((byte) 8);
timeConfig.setEndHour((byte) 10);
timeConfigService.saveOrUpdate(timeConfig);
}
@Test
public void saveErr() {
AlertTipTimeConfig timeConfig = new AlertTipTimeConfig();
timeConfig.setTimeName("123");
timeConfig.setTimeType(TipTimeConfig.EVENING_PEARK.name());
timeConfig.setStartHour((byte) 9);
timeConfig.setEndHour((byte) 8);
timeConfigService.saveOrUpdate(timeConfig);
}
@Test
public void bindTip() {
AlertTipSaveDTO dto = new AlertTipSaveDTO();
dto.setAlertType(AlertType.PLATFORM_DOOR_CANNOT_CLOSE);
dto.setTipTimeIds(List.of(1L));
alertTipService.save(dto);
}
@Test
public void quertTipPageLast() {
AlertTipQueryDTO dto = new AlertTipQueryDTO();
dto.setCurrent(25);
IPage<AlertTipInfoDto> page = alertTipService.page(dto);
System.out.println(JSON.toJSONString(page, Feature.PrettyFormat));
}
}

@ -1 +1 @@
Subproject commit da3fb50a050cb48ae2f90c082178ffaba6634967
Subproject commit 5034d44793497699ba8a2e5a2b6312e5a5b7e8f2