探测器新增代码同步

This commit is contained in:
qiaoqinzheng 2024-01-11 18:26:12 +08:00
parent 03955c3691
commit 63576edde8
5 changed files with 78 additions and 56 deletions

View File

@ -1,11 +1,15 @@
package org.jeecg.common.properties; package org.jeecg.common.properties;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant; import org.jeecg.common.constant.StringConstant;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Data @Data
@ -46,6 +50,30 @@ public class DetectorIdFormat {
return detectorId; return detectorId;
} }
public Integer detectorCodeToId(String detectorCode){
if (!StrUtil.contains(detectorCode, StrUtil.UNDERLINE))
return null;
String[] split = StrUtil.split(detectorCode, StrUtil.UNDERLINE);
String prefix = split[0];
String suffix = split[1];
// 根据台站code即prefix解析出Id的前半部分
prefix = StrUtil.sub(prefix, 2, prefix.length());
for (Map.Entry<String, String> entry : suffixMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (!StrUtil.contains(prefix, key))
continue;
prefix = StrUtil.replace(prefix, key, value);
}
if (!NumberUtil.isNumber(prefix))
return null;
// 根据探测器序号即suffix解析出Id的后半部分
if (!NumberUtil.isNumber(suffix))
return null;
suffix = String.format("%02d", Integer.valueOf(suffix));
return Integer.valueOf(prefix + suffix);
}
/** /**
* 格式化探测器id解析出台站id * 格式化探测器id解析出台站id
* @param detectorCode * @param detectorCode

View File

@ -5,12 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import org.jeecg.config.valid.InsertGroup;
import org.jeecg.config.valid.UpdateGroup;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -22,14 +18,12 @@ public class GardsDetectors implements Serializable {
* 探测器id * 探测器id
*/ */
@TableId(value = "DETECTOR_ID") @TableId(value = "DETECTOR_ID")
@NotNull(message = "不能为空", groups = {InsertGroup.class, UpdateGroup.class})
private Integer detectorId; private Integer detectorId;
/** /**
* 探测器编码 * 探测器编码
*/ */
@TableField(value = "DETECTOR_CODE") @TableField(value = "DETECTOR_CODE")
@NotBlank(message = "不能为空", groups = {InsertGroup.class, UpdateGroup.class})
private String detectorCode; private String detectorCode;
/** /**
@ -100,7 +94,6 @@ public class GardsDetectors implements Serializable {
* 操作时间 * 操作时间
*/ */
@TableField(value = "MODDATE") @TableField(value = "MODDATE")
@NotNull(message = "不能为空", groups = {InsertGroup.class, UpdateGroup.class})
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date moddate; private Date moddate;
@ -110,5 +103,4 @@ public class GardsDetectors implements Serializable {
*/ */
@TableField(value = "STATION_ID") @TableField(value = "STATION_ID")
private Integer stationId; private Integer stationId;
} }

View File

@ -0,0 +1,12 @@
package org.jeecg.modules.base.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum DetectorStatus {
ON("Operating"), OFF("Unoperating");
private final String value;
}

View File

@ -23,16 +23,16 @@
CONFIGURATION.GARDS_DETECTORS CONFIGURATION.GARDS_DETECTORS
<where> <where>
<if test="gardsDetectors.detectorCode != '' and gardsDetectors.detectorCode != null"> <if test="gardsDetectors.detectorCode != '' and gardsDetectors.detectorCode != null">
and DETECTOR_CODE like CONCAT('%',#{gardsDetectors.detectorCode},'%') DETECTOR_CODE LIKE CONCAT(CONCAT('%', #{gardsDetectors.detectorCode}), '%')
</if> </if>
<if test="gardsDetectors.type != '' and gardsDetectors.type != null"> <if test="gardsDetectors.type != '' and gardsDetectors.type != null">
and TYPE = #{gardsDetectors.type} AND TYPE = #{gardsDetectors.type}
</if> </if>
<if test="gardsDetectors.status != '' and gardsDetectors.status != null"> <if test="gardsDetectors.status != '' and gardsDetectors.status != null">
and RTRIM(STATUS, ' ') = #{gardsDetectors.status} AND RTRIM(STATUS, ' ') = #{gardsDetectors.status}
</if> </if>
</where> </where>
order by DETECTOR_ID asc Order By DETECTOR_ID ASC
</select> </select>
<select id="findType" resultType="java.lang.String"> <select id="findType" resultType="java.lang.String">

View File

@ -15,8 +15,10 @@ import com.google.common.collect.Lists;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.Prompt; import org.jeecg.common.constant.Prompt;
import org.jeecg.common.properties.DetectorIdFormat;
import org.jeecg.common.util.RedisUtil; import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.entity.configuration.GardsDetectors; import org.jeecg.modules.base.entity.configuration.GardsDetectors;
import org.jeecg.modules.base.enums.DetectorStatus;
import org.jeecg.modules.system.entity.GardsDetectorsSystem; import org.jeecg.modules.system.entity.GardsDetectorsSystem;
import org.jeecg.modules.system.mapper.GardsDetectorsMapper; import org.jeecg.modules.system.mapper.GardsDetectorsMapper;
import org.jeecg.modules.system.service.IGardsDetectorsService; import org.jeecg.modules.system.service.IGardsDetectorsService;
@ -31,9 +33,13 @@ import java.util.stream.Collectors;
@Service("gardsDetectorsService") @Service("gardsDetectorsService")
@DS("ora") @DS("ora")
public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper, GardsDetectorsSystem> implements IGardsDetectorsService { public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper, GardsDetectorsSystem> implements IGardsDetectorsService {
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired
private DetectorIdFormat idFormat;
@Override @Override
public Result<IPage<GardsDetectorsSystem>> findPage(QueryRequest queryRequest, GardsDetectorsSystem gardsDetectors) { public Result<IPage<GardsDetectorsSystem>> findPage(QueryRequest queryRequest, GardsDetectorsSystem gardsDetectors) {
Result<IPage<GardsDetectorsSystem>> result = new Result<>(); Result<IPage<GardsDetectorsSystem>> result = new Result<>();
@ -76,25 +82,28 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
@Override @Override
public List<String> findType() { public List<String> findType() {
List<String> type = this.baseMapper.findType(); return this.baseMapper.findType();
return type;
} }
@Override @Override
@Transactional @Transactional
public Result<?> create(GardsDetectorsSystem detector) { public Result<?> create(GardsDetectorsSystem detector) {
Integer detectorId = detector.getDetectorId();
String detectorCode = detector.getDetectorCode(); String detectorCode = detector.getDetectorCode();
LambdaQueryWrapper<GardsDetectorsSystem> wrapper = new LambdaQueryWrapper<>(); Integer detectorId = idFormat.detectorCodeToId(detectorCode);
wrapper.eq(GardsDetectors::getDetectorId, detectorId); if (ObjectUtil.isNull(detectorId))
wrapper.or().eq(GardsDetectors::getDetectorCode, detectorCode); return Result.error("Detector Code Is Invalid");
if (CollUtil.isNotEmpty(this.list(wrapper))) if (ObjectUtil.isNotNull(getById(detectorId)))
return Result.error("The detector id or code cannot be repeated"); return Result.error("Detector Code Cannot Repeated");
detector.setDetectorId(detectorId);
Integer stationId = detector.getStationId(); Integer stationId = detector.getStationId();
if (ObjectUtil.isNull(stationId))
return Result.error("Station id of the detector cannot be empty");
// 查询相同台站下所有工作的探测器 按照探测器Id升序排序 // 查询相同台站下所有工作的探测器 按照探测器Id升序排序
List<GardsDetectorsSystem> detectors = this.baseMapper.list(stationId, "Operating"); LambdaQueryWrapper<GardsDetectorsSystem> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsDetectors::getStationId, stationId);
List<GardsDetectorsSystem> detectors = this.list(wrapper);
detectors = detectors.stream()
.filter(item -> StrUtil.equals(StrUtil.trim(item.getStatus()), DetectorStatus.ON.getValue()))
.sorted(Comparator.comparingInt(GardsDetectorsSystem::getDetectorId))
.collect(Collectors.toList());
// 如果相同台站下没有工作探测器 // 如果相同台站下没有工作探测器
if (CollUtil.isEmpty(detectors)){ if (CollUtil.isEmpty(detectors)){
boolean success = this.save(detector); boolean success = this.save(detector);
@ -106,7 +115,7 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
} }
// 如果相同台站下有工作探测器 将Id最小的探测器状态置为 Unoperating // 如果相同台站下有工作探测器 将Id最小的探测器状态置为 Unoperating
GardsDetectorsSystem detectorMin = detectors.get(0); GardsDetectorsSystem detectorMin = detectors.get(0);
detectorMin.setStatus("Unoperating"); detectorMin.setStatus(DetectorStatus.OFF.getValue());
detectors = ListUtil.toList(detectorMin, detector); detectors = ListUtil.toList(detectorMin, detector);
boolean success = this.saveOrUpdateBatch(detectors); boolean success = this.saveOrUpdateBatch(detectors);
if (success){ if (success){
@ -117,41 +126,23 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
} }
@Override @Override
public Result update(GardsDetectorsSystem gardsDetectors) { public Result<?> update(GardsDetectorsSystem detector) {
Result result = new Result(); boolean success = this.updateById(detector);
LambdaQueryWrapper<GardsDetectorsSystem> wrapper = new LambdaQueryWrapper<>(); if (success){
wrapper.eq(GardsDetectorsSystem::getDetectorId, gardsDetectors.getDetectorId());
GardsDetectorsSystem stations = this.baseMapper.selectOne(wrapper);
if (Objects.isNull(stations)) {
result.error500("The current data does not existModification failure");
return result;
}
if (StringUtils.isNotBlank(gardsDetectors.getDetectorCode())){
LambdaQueryWrapper<GardsDetectorsSystem> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(GardsDetectorsSystem::getDetectorCode, gardsDetectors.getDetectorCode());
GardsDetectorsSystem detectors = this.baseMapper.selectOne(queryWrapper);
if (Objects.nonNull(detectors) && !detectors.getDetectorId().equals(gardsDetectors.getDetectorId())) {
result.error500("Current data "+gardsDetectors.getDetectorCode()+" Already existModification failure");
return result;
}
}
LambdaQueryWrapper<GardsDetectorsSystem> detectorsQueryWrapper = new LambdaQueryWrapper<>();
detectorsQueryWrapper.eq(GardsDetectorsSystem::getDetectorId, gardsDetectors.getDetectorId());
this.baseMapper.update(gardsDetectors, detectorsQueryWrapper);
result.success("Modified successfully");
this.findDetectors(); this.findDetectors();
return result; return Result.OK(Prompt.UPDATE_SUCC);
}
return Result.error(Prompt.UPDATE_ERR);
} }
@Override @Override
public Result deleteById(Integer id) { public Result<?> deleteById(Integer id) {
Result result = new Result(); boolean success = this.removeById(id);
LambdaQueryWrapper<GardsDetectorsSystem> queryWrapper = new LambdaQueryWrapper<>(); if (success){
queryWrapper.eq(GardsDetectorsSystem::getDetectorId, id);
this.baseMapper.delete(queryWrapper);
result.success("Successfully deleted");
this.findDetectors(); this.findDetectors();
return result; return Result.OK(Prompt.DELETE_SUCC);
}
return Result.error(Prompt.DELETE_ERR);
} }
@Override @Override
@ -179,5 +170,4 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
} }
return map; return map;
} }
} }