探测器新增代码同步
This commit is contained in:
parent
03955c3691
commit
63576edde8
|
@ -1,11 +1,15 @@
|
|||
package org.jeecg.common.properties;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.constant.StringConstant;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
|
@ -46,6 +50,30 @@ public class DetectorIdFormat {
|
|||
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
|
||||
* @param detectorCode
|
||||
|
|
|
@ -5,12 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.jeecg.config.valid.InsertGroup;
|
||||
import org.jeecg.config.valid.UpdateGroup;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -22,14 +18,12 @@ public class GardsDetectors implements Serializable {
|
|||
* 探测器id
|
||||
*/
|
||||
@TableId(value = "DETECTOR_ID")
|
||||
@NotNull(message = "不能为空", groups = {InsertGroup.class, UpdateGroup.class})
|
||||
private Integer detectorId;
|
||||
|
||||
/**
|
||||
* 探测器编码
|
||||
*/
|
||||
@TableField(value = "DETECTOR_CODE")
|
||||
@NotBlank(message = "不能为空", groups = {InsertGroup.class, UpdateGroup.class})
|
||||
private String detectorCode;
|
||||
|
||||
/**
|
||||
|
@ -100,7 +94,6 @@ public class GardsDetectors implements Serializable {
|
|||
* 操作时间
|
||||
*/
|
||||
@TableField(value = "MODDATE")
|
||||
@NotNull(message = "不能为空", groups = {InsertGroup.class, UpdateGroup.class})
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date moddate;
|
||||
|
@ -110,5 +103,4 @@ public class GardsDetectors implements Serializable {
|
|||
*/
|
||||
@TableField(value = "STATION_ID")
|
||||
private Integer stationId;
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -23,16 +23,16 @@
|
|||
CONFIGURATION.GARDS_DETECTORS
|
||||
<where>
|
||||
<if test="gardsDetectors.detectorCode != '' and gardsDetectors.detectorCode != null">
|
||||
and DETECTOR_CODE like CONCAT('%',#{gardsDetectors.detectorCode},'%')
|
||||
DETECTOR_CODE LIKE CONCAT(CONCAT('%', #{gardsDetectors.detectorCode}), '%')
|
||||
</if>
|
||||
<if test="gardsDetectors.type != '' and gardsDetectors.type != null">
|
||||
and TYPE = #{gardsDetectors.type}
|
||||
AND TYPE = #{gardsDetectors.type}
|
||||
</if>
|
||||
<if test="gardsDetectors.status != '' and gardsDetectors.status != null">
|
||||
and RTRIM(STATUS, ' ') = #{gardsDetectors.status}
|
||||
AND RTRIM(STATUS, ' ') = #{gardsDetectors.status}
|
||||
</if>
|
||||
</where>
|
||||
order by DETECTOR_ID asc
|
||||
Order By DETECTOR_ID ASC
|
||||
</select>
|
||||
|
||||
<select id="findType" resultType="java.lang.String">
|
||||
|
|
|
@ -15,8 +15,10 @@ import com.google.common.collect.Lists;
|
|||
import org.jeecg.common.api.QueryRequest;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.Prompt;
|
||||
import org.jeecg.common.properties.DetectorIdFormat;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
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.mapper.GardsDetectorsMapper;
|
||||
import org.jeecg.modules.system.service.IGardsDetectorsService;
|
||||
|
@ -31,9 +33,13 @@ import java.util.stream.Collectors;
|
|||
@Service("gardsDetectorsService")
|
||||
@DS("ora")
|
||||
public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper, GardsDetectorsSystem> implements IGardsDetectorsService {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Autowired
|
||||
private DetectorIdFormat idFormat;
|
||||
|
||||
@Override
|
||||
public Result<IPage<GardsDetectorsSystem>> findPage(QueryRequest queryRequest, GardsDetectorsSystem gardsDetectors) {
|
||||
Result<IPage<GardsDetectorsSystem>> result = new Result<>();
|
||||
|
@ -76,25 +82,28 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
|
|||
|
||||
@Override
|
||||
public List<String> findType() {
|
||||
List<String> type = this.baseMapper.findType();
|
||||
return type;
|
||||
return this.baseMapper.findType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<?> create(GardsDetectorsSystem detector) {
|
||||
Integer detectorId = detector.getDetectorId();
|
||||
String detectorCode = detector.getDetectorCode();
|
||||
LambdaQueryWrapper<GardsDetectorsSystem> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(GardsDetectors::getDetectorId, detectorId);
|
||||
wrapper.or().eq(GardsDetectors::getDetectorCode, detectorCode);
|
||||
if (CollUtil.isNotEmpty(this.list(wrapper)))
|
||||
return Result.error("The detector id or code cannot be repeated");
|
||||
Integer detectorId = idFormat.detectorCodeToId(detectorCode);
|
||||
if (ObjectUtil.isNull(detectorId))
|
||||
return Result.error("Detector Code Is Invalid");
|
||||
if (ObjectUtil.isNotNull(getById(detectorId)))
|
||||
return Result.error("Detector Code Cannot Repeated");
|
||||
detector.setDetectorId(detectorId);
|
||||
Integer stationId = detector.getStationId();
|
||||
if (ObjectUtil.isNull(stationId))
|
||||
return Result.error("Station id of the detector cannot be empty");
|
||||
// 查询相同台站下所有工作的探测器 按照探测器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)){
|
||||
boolean success = this.save(detector);
|
||||
|
@ -106,7 +115,7 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
|
|||
}
|
||||
// 如果相同台站下有工作探测器 将Id最小的探测器状态置为 Unoperating
|
||||
GardsDetectorsSystem detectorMin = detectors.get(0);
|
||||
detectorMin.setStatus("Unoperating");
|
||||
detectorMin.setStatus(DetectorStatus.OFF.getValue());
|
||||
detectors = ListUtil.toList(detectorMin, detector);
|
||||
boolean success = this.saveOrUpdateBatch(detectors);
|
||||
if (success){
|
||||
|
@ -117,41 +126,23 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result update(GardsDetectorsSystem gardsDetectors) {
|
||||
Result result = new Result();
|
||||
LambdaQueryWrapper<GardsDetectorsSystem> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(GardsDetectorsSystem::getDetectorId, gardsDetectors.getDetectorId());
|
||||
GardsDetectorsSystem stations = this.baseMapper.selectOne(wrapper);
|
||||
if (Objects.isNull(stations)) {
|
||||
result.error500("The current data does not exist,Modification failure");
|
||||
return result;
|
||||
public Result<?> update(GardsDetectorsSystem detector) {
|
||||
boolean success = this.updateById(detector);
|
||||
if (success){
|
||||
this.findDetectors();
|
||||
return Result.OK(Prompt.UPDATE_SUCC);
|
||||
}
|
||||
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 exist,Modification 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();
|
||||
return result;
|
||||
return Result.error(Prompt.UPDATE_ERR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result deleteById(Integer id) {
|
||||
Result result = new Result();
|
||||
LambdaQueryWrapper<GardsDetectorsSystem> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(GardsDetectorsSystem::getDetectorId, id);
|
||||
this.baseMapper.delete(queryWrapper);
|
||||
result.success("Successfully deleted");
|
||||
this.findDetectors();
|
||||
return result;
|
||||
public Result<?> deleteById(Integer id) {
|
||||
boolean success = this.removeById(id);
|
||||
if (success){
|
||||
this.findDetectors();
|
||||
return Result.OK(Prompt.DELETE_SUCC);
|
||||
}
|
||||
return Result.error(Prompt.DELETE_ERR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -179,5 +170,4 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
|
|||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user