You've already forked FrameTour-BE
模板、设备排序
This commit is contained in:
@ -3,6 +3,7 @@ package com.ycwl.basic.service.impl.pc;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
|
||||
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
|
||||
import com.ycwl.basic.model.wvp.WvpSyncReqVo;
|
||||
import com.ycwl.basic.repository.DeviceRepository;
|
||||
import com.ycwl.basic.mapper.DeviceMapper;
|
||||
@ -18,6 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
@ -123,4 +126,37 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Boolean> sortDevice(Long deviceId, Long afterDeviceId) {
|
||||
DeviceEntity device = deviceRepository.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
return ApiResponse.fail("设备不存在");
|
||||
}
|
||||
List<DeviceEntity> scenicDeviceList = deviceRepository.getAllDeviceByScenicId(device.getScenicId());
|
||||
AtomicInteger sortNum = new AtomicInteger(0);
|
||||
for (DeviceEntity item : scenicDeviceList) {
|
||||
item.setSort(sortNum.addAndGet(1));
|
||||
}
|
||||
Optional<DeviceEntity> templateOptional = scenicDeviceList.stream().filter(item -> item.getId().equals(deviceId)).findAny();
|
||||
Optional<DeviceEntity> afterTemplateOptional = scenicDeviceList.stream().filter(item -> item.getId().equals(afterDeviceId)).findAny();
|
||||
if (!templateOptional.isPresent()) {
|
||||
return ApiResponse.fail("设备不存在");
|
||||
}
|
||||
if (afterTemplateOptional.isPresent()) {
|
||||
DeviceEntity afterTemplate = afterTemplateOptional.get();
|
||||
Integer newSort = afterTemplate.getSort();
|
||||
DeviceEntity oldTemplate = templateOptional.get();
|
||||
Integer oldSort = oldTemplate.getSort();
|
||||
afterTemplate.setSort(oldSort);
|
||||
oldTemplate.setSort(newSort);
|
||||
}
|
||||
scenicDeviceList.forEach(item -> {
|
||||
deviceMapper.updateSort(item.getId(), item.getSort());
|
||||
deviceRepository.clearDeviceCache(item.getId());
|
||||
deviceRepository.clearDeviceCache(item.getNo());
|
||||
deviceRepository.clearDeviceCache(item.getNo2());
|
||||
});
|
||||
return ApiResponse.success(true);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
@ -123,4 +125,35 @@ public class TemplateServiceImpl implements TemplateService {
|
||||
templateMapper.updateConfigById(config);
|
||||
templateRepository.clearTemplateCache(config.getTemplateId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<Boolean> sortTemplate(Long templateId, Long afterTemplateId) {
|
||||
TemplateRespVO template = templateRepository.getTemplate(templateId);
|
||||
if (template == null) {
|
||||
return ApiResponse.fail("模版不存在");
|
||||
}
|
||||
List<TemplateRespVO> scenicTemplateList = templateRepository.getAllTemplateListByScenicId(template.getScenicId());
|
||||
AtomicInteger sortNum = new AtomicInteger(0);
|
||||
for (TemplateRespVO item : scenicTemplateList) {
|
||||
item.setSort(sortNum.addAndGet(1));
|
||||
}
|
||||
Optional<TemplateRespVO> templateOptional = scenicTemplateList.stream().filter(item -> item.getId().equals(templateId)).findAny();
|
||||
Optional<TemplateRespVO> afterTemplateOptional = scenicTemplateList.stream().filter(item -> item.getId().equals(afterTemplateId)).findAny();
|
||||
if (!templateOptional.isPresent()) {
|
||||
return ApiResponse.fail("模版不存在");
|
||||
}
|
||||
if (afterTemplateOptional.isPresent()) {
|
||||
TemplateRespVO afterTemplate = afterTemplateOptional.get();
|
||||
Integer newSort = afterTemplate.getSort();
|
||||
TemplateRespVO oldTemplate = templateOptional.get();
|
||||
Integer oldSort = oldTemplate.getSort();
|
||||
afterTemplate.setSort(oldSort);
|
||||
oldTemplate.setSort(newSort);
|
||||
}
|
||||
scenicTemplateList.forEach(item -> {
|
||||
templateMapper.updateSort(item.getId(), item.getSort());
|
||||
templateRepository.clearTemplateCache(item.getId());
|
||||
});
|
||||
return ApiResponse.success(true);
|
||||
}
|
||||
}
|
||||
|
@ -27,4 +27,6 @@ public interface DeviceService {
|
||||
void saveConfig(Long configId, DeviceConfigEntity config);
|
||||
|
||||
void updateDevices(Long scenicId, WvpSyncReqVo reqVo);
|
||||
|
||||
ApiResponse<Boolean> sortDevice(Long deviceId, Long afterDeviceId);
|
||||
}
|
||||
|
@ -26,4 +26,6 @@ public interface TemplateService {
|
||||
TemplateConfigEntity getConfig(Long templateId);
|
||||
|
||||
void saveConfig(Long configId, TemplateConfigEntity config);
|
||||
|
||||
ApiResponse<Boolean> sortTemplate(Long templateId, Long afterTemplateId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user