package com.lxzn.nc.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.lxzn.framework.domain.nc.DeviceType;
|
import com.lxzn.framework.domain.nc.response.DeviceCode;
|
import com.lxzn.framework.domain.nc.response.ProcessInfoCode;
|
import com.lxzn.framework.exception.ExceptionCast;
|
import com.lxzn.framework.model.response.CommonCode;
|
import com.lxzn.framework.utils.ValidateUtil;
|
import com.lxzn.nc.dao.DeviceTypeMapper;
|
import com.lxzn.nc.service.IDeviceTypeService;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
@Service
|
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements IDeviceTypeService {
|
|
|
/**
|
* 新增设备类
|
* @param deviceType
|
* @return
|
*/
|
@Override
|
public boolean add(DeviceType deviceType){
|
|
//已启动设备类
|
if(!ValidateUtil.validateString(deviceType.getAttributionId()))
|
ExceptionCast.cast(DeviceCode.DEVICE_CLASS_ERROR);
|
List<DeviceType> deviceTypes=this.getByProductionIdAndDeviceManagementId(deviceType);
|
if(!deviceTypes.isEmpty()){
|
ExceptionCast.cast(DeviceCode.DEVICE_CLASS_NAME_EXIST);
|
}
|
return this.save(deviceType);
|
}
|
/**
|
* 编辑设备类
|
* @param deviceType
|
* @return
|
*/
|
@Override
|
public boolean edit(DeviceType deviceType){
|
if(deviceType == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(deviceType.getDeviceManagementId()==null)
|
ExceptionCast.cast(ProcessInfoCode.PROCESS_NAME_NONE);
|
DeviceType en = super.getById(deviceType.getId());
|
if(en == null)
|
ExceptionCast.cast(DeviceCode.DEVICE_CLASS_ERROR);
|
//判断设备类是否为本身
|
if(en.getDeviceManagementId().equals(deviceType.getDeviceManagementId())
|
&&en.getProductionId().equals(deviceType.getProductionId())
|
&&en.getAttributionId().equals(deviceType.getAttributionId())
|
&&en.getAttributionType().equals(deviceType.getAttributionType())){
|
return true;
|
}
|
//判断设备类是否被使用
|
List<DeviceType> deviceTypeList=this.getByProductionIdAndDeviceManagementId(deviceType);
|
if(!deviceTypeList.isEmpty()){
|
ExceptionCast.cast(DeviceCode.DEVICE_CLASS_EXIST);
|
}
|
return this.updateById(deviceType);
|
}
|
/**
|
* 根据id删除设备类
|
* @param id
|
* @return
|
*/
|
@Override
|
public boolean delete(String id){
|
if(!ValidateUtil.validateString(id))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
DeviceType en = super.getById(id);
|
if(en == null)
|
ExceptionCast.cast(DeviceCode.DEVICE_CLASS_ERROR);
|
return super.removeById(id);
|
}
|
|
|
/**
|
* 通过车间id与设备类id查询设备信息
|
* @param deviceType
|
* @return
|
*/
|
public List<DeviceType> getByProductionIdAndDeviceManagementId(DeviceType deviceType) {
|
List<DeviceType> list = this.list(new QueryWrapper<DeviceType>().eq("attribution_id", deviceType.getAttributionId())
|
.eq("attribution_type", deviceType.getAttributionType())
|
.eq("device_management_id", deviceType.getDeviceManagementId()));
|
// list.forEach(item->{
|
// item.setDeviceManagementCode(item.getDeviceManagementId());
|
// });
|
return list;
|
}
|
|
|
/**
|
* 根据业务id查询设备类列表
|
* @param businessId
|
* @param type
|
* @return
|
*/
|
@Override
|
public List<DeviceType> getByBusinessId(String businessId,String type){
|
List<DeviceType> list = this.list(new QueryWrapper<DeviceType>().eq("attribution_id", businessId).eq("attribution_type", type));
|
// list.forEach(item->{
|
// item.setDeviceManagementCode(item.getDeviceManagementId());
|
// });
|
return list;
|
}
|
}
|