feat: 增加rptparam的查询修改功能
parent
f3da1a85d0
commit
394604915a
@ -0,0 +1,56 @@
|
|||||||
|
package com.xydl.cac.controller;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Rptparamindex;
|
||||||
|
import com.xydl.cac.exception.BusinessException;
|
||||||
|
import com.xydl.cac.model.BindDetail;
|
||||||
|
import com.xydl.cac.model.BindingModel;
|
||||||
|
import com.xydl.cac.model.Response;
|
||||||
|
import com.xydl.cac.service.ParamIndexService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Api(tags = {"rptparam相关接口"})
|
||||||
|
@RequestMapping("rptparam")
|
||||||
|
@Slf4j
|
||||||
|
public class ParamIndexController extends BasicController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ParamIndexService service;
|
||||||
|
|
||||||
|
@GetMapping("listRpt")
|
||||||
|
@ApiOperation("查询可用rptparam")
|
||||||
|
public Response<List<Rptparamindex>> listRpt(String param) throws Exception {
|
||||||
|
if (param == null) {
|
||||||
|
throw new BusinessException("param不能为空!");
|
||||||
|
}
|
||||||
|
List<Rptparamindex> result = service.listRpt(param);
|
||||||
|
return Response.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("getRpt")
|
||||||
|
@ApiOperation("查询绑定信息")
|
||||||
|
public Response<BindDetail> getRpt(@Validated @NotNull(message = "sensorId不能为空!") @Param("sensorId") Integer sensorId) throws Exception {
|
||||||
|
if (sensorId == null) {
|
||||||
|
throw new BusinessException("sensorId不能为空!");
|
||||||
|
}
|
||||||
|
BindDetail result = service.getRpt(sensorId);
|
||||||
|
return Response.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("updateRpt")
|
||||||
|
@ApiOperation("绑定")
|
||||||
|
public Response<String> updateRpt(@Validated @RequestBody BindingModel item) throws Exception {
|
||||||
|
service.updateRpt(item);
|
||||||
|
return Response.success("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Rptparamindex;
|
||||||
|
import com.xydl.cac.model.BindDetail;
|
||||||
|
import com.xydl.cac.model.BindingModel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ParamIndexService {
|
||||||
|
|
||||||
|
List<Rptparamindex> listRpt(String param);
|
||||||
|
|
||||||
|
BindDetail getRpt(Integer sensorId) throws Exception;
|
||||||
|
|
||||||
|
void updateRpt(BindingModel item) throws Exception;
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package com.xydl.cac.service.impl;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.*;
|
||||||
|
import com.xydl.cac.exception.BusinessException;
|
||||||
|
import com.xydl.cac.model.BindDetail;
|
||||||
|
import com.xydl.cac.model.BindingModel;
|
||||||
|
import com.xydl.cac.model.ColumnModel;
|
||||||
|
import com.xydl.cac.repository.*;
|
||||||
|
import com.xydl.cac.service.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ParamIndexServiceImpl implements ParamIndexService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
NSensorRepository sensorRepository;
|
||||||
|
@Resource
|
||||||
|
ModevTypeService modevTypeService;
|
||||||
|
@Resource
|
||||||
|
IcdFileConfigService configService;
|
||||||
|
@Resource
|
||||||
|
RptparamindexRepository rptparamindexRepository;
|
||||||
|
@Resource
|
||||||
|
ParamBindService bindService;
|
||||||
|
@Resource
|
||||||
|
DataService dataService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Rptparamindex> listRpt(String param) {
|
||||||
|
List<Rptparamindex> list = rptparamindexRepository.findAllByParamindexStartingWith(param);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BindDetail getRpt(Integer sensorId) throws Exception {
|
||||||
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(sensorId);
|
||||||
|
if (!optionalNSensor.isPresent()) {
|
||||||
|
throw new BusinessException("未找到该监测装置");
|
||||||
|
}
|
||||||
|
NSensor sensor = optionalNSensor.get();
|
||||||
|
ModevType modevType = modevTypeService.detail(sensor.getTypeId());
|
||||||
|
sensor.setTableName(modevType.getTablename());
|
||||||
|
|
||||||
|
BindDetail result = new BindDetail();
|
||||||
|
result.setSensorId(sensorId);
|
||||||
|
if (StringUtils.isNotBlank(sensor.getTableName())) {
|
||||||
|
List<ColumnModel> columnList = dataService.getDataTableColumns(sensor.getTableName());
|
||||||
|
result.setColumnList(columnList);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Rptparamindex> rptList = rptparamindexRepository.findAllByEqmid(sensor.getDevId());
|
||||||
|
result.setRptList(rptList);
|
||||||
|
if (!CollectionUtils.isEmpty(rptList)) {
|
||||||
|
this.findMatchIed(result, rptList.get(0).getParamindex());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void findMatchIed(BindDetail result, String paramindex) {
|
||||||
|
List<String> iedList = configService.iedList();
|
||||||
|
for (String ied : iedList) {
|
||||||
|
if (paramindex.startsWith(ied)) {
|
||||||
|
List<IcdConfigTypeInst> instList = bindService.instList(ied);
|
||||||
|
for (IcdConfigTypeInst inst : instList) {
|
||||||
|
if (paramindex.startsWith(inst.getParamIndex())) {
|
||||||
|
result.setIcdid(inst.getId());
|
||||||
|
result.setIedName(ied);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateRpt(BindingModel item) throws Exception {
|
||||||
|
Optional<NSensor> optionalNSensor = sensorRepository.findById(item.getSensorId());
|
||||||
|
if (!optionalNSensor.isPresent()) {
|
||||||
|
throw new BusinessException("未找到该监测装置");
|
||||||
|
}
|
||||||
|
NSensor sensor = optionalNSensor.get();
|
||||||
|
ModevType modevType = modevTypeService.detail(sensor.getTypeId());
|
||||||
|
sensor.setTableName(modevType.getTablename());
|
||||||
|
|
||||||
|
// 清除旧的
|
||||||
|
List<Rptparamindex> rptList = rptparamindexRepository.findAllByEqmid(sensor.getDevId());
|
||||||
|
for (Rptparamindex rpt : rptList) {
|
||||||
|
rpt.setEqmid(null);
|
||||||
|
rpt.setColname(null);
|
||||||
|
rpt.setTablename(null);
|
||||||
|
rptparamindexRepository.save(rpt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置新的
|
||||||
|
for (Rptparamindex rpt : item.getRptList()) {
|
||||||
|
Optional<Rptparamindex> optional = rptparamindexRepository.findById(rpt.getParamindex());
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
Rptparamindex record = optional.get();
|
||||||
|
record.setTablename(sensor.getTableName());
|
||||||
|
record.setEqmid(sensor.getDevId());
|
||||||
|
record.setColname(rpt.getColname());
|
||||||
|
rptparamindexRepository.save(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue