package com.yuanchu.mom.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.yuanchu.mom.pojo.Device;
|
import com.yuanchu.mom.mapper.DeviceMapper;
|
import com.yuanchu.mom.pojo.RawInsProduct;
|
import com.yuanchu.mom.service.DeviceService;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.yuanchu.mom.service.RawInsProductService;
|
import com.yuanchu.mom.utils.MyUtil;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* <p>
|
* 服务实现类
|
* </p>
|
*
|
* @author 江苏鵷雏网络科技有限公司
|
* @since 2023-07-31
|
*/
|
@Service
|
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
|
|
@Resource
|
private DeviceMapper deviceMapper;
|
|
@Resource
|
private RawInsProductService rawInsProductService;
|
|
@Override
|
public Map<String, Object> selectTechnology(String deviceGroup) {
|
String[] split = deviceGroup.split("\\+");
|
Map<String, Object> map = new HashMap<>();
|
for (String str : split){
|
LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(Device::getFather, str);
|
wrapper.select(Device::getId, Device::getName);
|
List<Map<String, Object>> maps = deviceMapper.selectMaps(wrapper);
|
map.put("first", str);
|
map.put("children", maps);
|
}
|
return map;
|
}
|
|
//查询所有设备
|
@Override
|
public List<Device> selectDevice() {
|
return deviceMapper.selectList(new QueryWrapper<>());
|
}
|
|
//根据设备id获取设备名称
|
@Override
|
public String getDeviceNameById(Integer id) {
|
Device device = deviceMapper.selectById(id);
|
return device.getName();
|
}
|
|
@Override
|
public Boolean addDevice(Device device) {
|
int insert = deviceMapper.insert(device);
|
if (insert == 1){
|
LambdaUpdateWrapper<RawInsProduct> updateWrapper = new LambdaUpdateWrapper<>();
|
updateWrapper.eq(RawInsProduct::getId, device.getRawInsProductId());
|
updateWrapper.set(RawInsProduct::getDeviceId, device.getId());
|
return rawInsProductService.update(updateWrapper);
|
}
|
|
return false;
|
}
|
|
@Override
|
public List<Map<String, Object>> deviceTwoTree(Integer type, String search_class) {
|
return deviceMapper.deviceTwoTree(type, search_class);
|
}
|
|
@Override
|
public List<Map<String, Object>> DevicePageList(String codeNameModel,Integer type, Integer deviceStatue, Integer deviceId, String fatherName) {
|
return deviceMapper.DevicePageList(codeNameModel, type, deviceStatue, deviceId, fatherName);
|
}
|
|
@Override
|
public Integer deviceDelete(Integer deviceId) {
|
LambdaUpdateWrapper<Device> updateWrapper = new LambdaUpdateWrapper<>();
|
updateWrapper.eq(Device::getId, deviceId);
|
updateWrapper.set(Device::getState, 0);
|
return deviceMapper.update(new Device(), updateWrapper);
|
}
|
|
@Override
|
public Integer deviceDeleteIdOrFather(Integer id, String deviceFather) {
|
LambdaUpdateWrapper<Device> updateWrapper = new LambdaUpdateWrapper<>();
|
updateWrapper.set(Device::getState, 0);
|
if (id != null) {
|
updateWrapper.eq(Device::getId, id);
|
} else if (deviceFather != null) {
|
updateWrapper.eq(Device::getFather, deviceFather);
|
}
|
return deviceMapper.update(new Device(), updateWrapper);
|
}
|
}
|