parent
2f4cc28e83
commit
47ff18e96e
@ -0,0 +1,34 @@ |
||||
package com.bellmann.controller; |
||||
|
||||
import com.bellmann.common.result.Result; |
||||
import com.bellmann.plugin.dupsubmit.annotation.PreventDuplicateSubmit; |
||||
import com.bellmann.service.Ipv6ConfigService; |
||||
import io.swagger.v3.oas.annotations.Operation; |
||||
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.security.access.prepost.PreAuthorize; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
@Tag(name = "32.IPV6采集配置") |
||||
@RestController |
||||
@RequiredArgsConstructor |
||||
@RequestMapping("/api/ipv6-collection-config/v1") |
||||
public class Ipv6ConfigController { |
||||
|
||||
private final Ipv6ConfigService ipv6ConfigService; |
||||
@PutMapping("/{param1}/{param2}") |
||||
@PreAuthorize("@ss.hasPerm('update:ipv6:config:param')") |
||||
@Operation(summary = "修改Ipv6采集配置信息") |
||||
public Result<String> updateIpv6ConfigParam(@PathVariable String param1, @PathVariable String param2){ |
||||
return ipv6ConfigService.updateIpv6ConfigParam(param1,param2); |
||||
} |
||||
@PostMapping("upload") |
||||
@PreventDuplicateSubmit |
||||
@PreAuthorize("@ss.hasPerm('ipv6:config:upload')") |
||||
@Operation(summary = "提交文件") |
||||
public Result<String> upload(@RequestPart("file") MultipartFile file){ |
||||
ipv6ConfigService.saveIptvCollectDeviceFile(file); |
||||
return Result.success(); |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
package com.bellmann.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.bellmann.model.entity.CollectDeviceInfo; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface CollectDeviceInfoMapper extends BaseMapper<CollectDeviceInfo> { |
||||
} |
@ -0,0 +1,9 @@ |
||||
package com.bellmann.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.bellmann.model.entity.DataDict; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface DataDictMapper extends BaseMapper<DataDict> { |
||||
} |
@ -0,0 +1,17 @@ |
||||
package com.bellmann.model.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDateTime; |
||||
|
||||
@Data |
||||
@TableName("itms_collect_device_info") |
||||
public class CollectDeviceInfo implements Serializable { |
||||
private static final long serialVersionUID = 8066420349940510058L; |
||||
|
||||
private LocalDateTime createTime; |
||||
|
||||
private String devSno; |
||||
} |
@ -0,0 +1,22 @@ |
||||
package com.bellmann.model.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
@TableName("ITMS_DATA_DICT") |
||||
public class DataDict implements Serializable { |
||||
private static final long serialVersionUID = 4589238922561407879L; |
||||
|
||||
private String tableName; |
||||
|
||||
private String columnName; |
||||
|
||||
private String value; |
||||
|
||||
private String key; |
||||
|
||||
private String delFlag; |
||||
} |
@ -0,0 +1,10 @@ |
||||
package com.bellmann.service; |
||||
|
||||
import com.bellmann.common.result.Result; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
public interface Ipv6ConfigService { |
||||
Result<String> updateIpv6ConfigParam(String param1, String param2); |
||||
|
||||
void saveIptvCollectDeviceFile(MultipartFile file); |
||||
} |
@ -0,0 +1,97 @@ |
||||
package com.bellmann.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
import com.bellmann.common.exception.BusinessException; |
||||
import com.bellmann.common.result.Result; |
||||
import com.bellmann.common.result.ResultCode; |
||||
import com.bellmann.mapper.CollectDeviceInfoMapper; |
||||
import com.bellmann.mapper.DataDictMapper; |
||||
import com.bellmann.model.entity.CollectDeviceInfo; |
||||
import com.bellmann.model.entity.DataDict; |
||||
import com.bellmann.service.Ipv6ConfigService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.InputStreamReader; |
||||
import java.time.LocalDateTime; |
||||
|
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class Ipv6ConfigServiceImpl implements Ipv6ConfigService { |
||||
|
||||
private final DataDictMapper dataDictMapper; |
||||
|
||||
private final CollectDeviceInfoMapper collectDeviceInfoMapper; |
||||
|
||||
@Override |
||||
@Transactional |
||||
public Result<String> updateIpv6ConfigParam(String param1, String param2) { |
||||
String column = ""; |
||||
if ("subAreaId".equals(param1)) { |
||||
column = "itms_device_static.region_area_id"; |
||||
} |
||||
if ("areaId".equalsIgnoreCase(param1)) { |
||||
// 选择地市时需要自动匹配地市下所有区县
|
||||
|
||||
column = "areaId"; |
||||
} |
||||
if ("deviceTypeId".equalsIgnoreCase(param1)) { |
||||
column = "itms_device_type.dev_type_name"; |
||||
} |
||||
if ("routeId".equalsIgnoreCase(param1)) { |
||||
column = "itms_device_service_args.args_value"; |
||||
} |
||||
if ("collectStrId".equalsIgnoreCase(param1)) { |
||||
column = ""; |
||||
} |
||||
if (!"".equals(param1)) { |
||||
dataDictMapper.update(null, new LambdaUpdateWrapper<DataDict>() |
||||
.eq(DataDict::getKey, column) |
||||
.eq(DataDict::getTableName, "ITMS_IPV6_COLLECT_INFO") |
||||
.set(DataDict::getValue, param2) |
||||
); |
||||
dataDictMapper.update(null, new LambdaUpdateWrapper<DataDict>() |
||||
.eq(DataDict::getKey, "FLAG") |
||||
.eq(DataDict::getTableName, "ITMS_IPV6_COLLECT_INFO") |
||||
.set(DataDict::getValue, "0") |
||||
); |
||||
return Result.success(); |
||||
} |
||||
return Result.failed(); |
||||
} |
||||
|
||||
@Override |
||||
@Transactional |
||||
public void saveIptvCollectDeviceFile(MultipartFile file) { |
||||
if (file==null){ |
||||
throw new BusinessException(ResultCode.FILE_NOT_EXIST); |
||||
} |
||||
String originalFilename = file.getOriginalFilename(); |
||||
assert originalFilename != null; |
||||
int dotIndex = originalFilename.lastIndexOf('.'); |
||||
String extension = originalFilename.substring(dotIndex + 1); |
||||
if (!"txt".equals(extension)){ |
||||
throw new BusinessException(ResultCode.PLEASE_UPLOAD_THE_TXT_FILE_TYPE); |
||||
} |
||||
try (InputStreamReader in = new InputStreamReader(file.getInputStream()); |
||||
BufferedReader br = new BufferedReader(in);) { |
||||
String content = ""; |
||||
while ((content = br.readLine()) != null) { |
||||
CollectDeviceInfo collectDeviceInfo = new CollectDeviceInfo(); |
||||
collectDeviceInfo.setCreateTime(LocalDateTime.now()); |
||||
collectDeviceInfo.setDevSno(content); |
||||
collectDeviceInfoMapper.insert(collectDeviceInfo); |
||||
} |
||||
dataDictMapper.update(null, new LambdaUpdateWrapper<DataDict>() |
||||
.eq(DataDict::getKey, "FLAG") |
||||
.eq(DataDict::getTableName, "ITMS_IPV6_COLLECT_INFO") |
||||
.set(DataDict::getValue, "1") |
||||
); |
||||
} catch (Exception e) { |
||||
throw new BusinessException(ResultCode.FAILED_TO_READ_DEVICE_SEQUENCE_FILE); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue