package org.jeecg.modules.dnc.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.modules.dnc.entity.DeviceType;
|
import org.jeecg.modules.dnc.exception.ExceptionCast;
|
import org.jeecg.modules.dnc.mapper.DeviceTypeMapper;
|
import org.jeecg.modules.dnc.response.CommonCode;
|
import org.jeecg.modules.dnc.response.ProcessInfoCode;
|
import org.jeecg.modules.dnc.service.IDeviceTypeService;
|
import org.jeecg.modules.dnc.utils.ValidateUtil;
|
import org.jeecg.modules.system.entity.SysParams;
|
import org.jeecg.modules.system.service.ISysParamsService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
@Service
|
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements IDeviceTypeService {
|
|
@Autowired
|
private ISysParamsService sysParamsService;
|
|
/**
|
* 新增设备类
|
* @param deviceType
|
* @return
|
*/
|
@Override
|
public Result<?> add(DeviceType deviceType){
|
SysParams sysParams;
|
if (deviceType.getAttributionType()==5){
|
//工序设备类
|
sysParams = sysParamsService.getSysPramBySettingKey("dnc_device_type_process");
|
}else {
|
//工步设备类
|
sysParams = sysParamsService.getSysPramBySettingKey("dnc_device_type_step");
|
}
|
if ("0".equals(sysParams.getSettingValue())){
|
//未启动设备类
|
return Result.error("设备类未启动,请联系管理员");
|
}else {
|
//已启动设备类
|
if(!ValidateUtil.validateString(deviceType.getAttributionId()))
|
Result.error("无效的设备类");
|
List<DeviceType> deviceTypes=this.getByProductionIdAndDeviceManagementId(deviceType);
|
if(!deviceTypes.isEmpty()){
|
return Result.error("设备类名称已存在");
|
}
|
boolean save = this.save(deviceType);
|
if(save){
|
return Result.OK("添加设备类成功");
|
}
|
return Result.error("新增设备类失败");
|
}
|
}
|
/**
|
* 编辑设备类
|
* @param deviceType
|
* @return
|
*/
|
@Override
|
public Result<?> 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(ProcessInfoCode.WORKSTEP_NOT_EXIST);
|
//判断设备类是否为本身
|
if(en.getDeviceManagementId().equals(deviceType.getDeviceManagementId())
|
&&en.getProductionId().equals(deviceType.getProductionId())
|
&&en.getAttributionId().equals(deviceType.getAttributionId())
|
&&en.getAttributionType().equals(deviceType.getAttributionType())){
|
return Result.OK("设备类编辑成功");
|
}
|
//判断设备类是否被使用
|
List<DeviceType> deviceTypeList=this.getByProductionIdAndDeviceManagementId(deviceType);
|
if(!deviceTypeList.isEmpty()){
|
return Result.error("设备类已存在");
|
}
|
boolean save = this.updateById(deviceType);
|
if(save){
|
return Result.OK("设备类编辑成功");
|
}
|
return Result.OK("设备类编辑失败");
|
}
|
/**
|
* 根据id删除设备类
|
* @param id
|
* @return
|
*/
|
@Override
|
public Result<?> delete(String id){
|
if(!ValidateUtil.validateString(id))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
DeviceType en = super.getById(id);
|
if(en == null)
|
return Result.error("无效的设备类");
|
boolean b=super.removeById(id);
|
if(!b) {
|
return Result.error("删除设备类失败");
|
}
|
return Result.OK("删除设备类成功");
|
}
|
|
/**
|
* 根据设备类信息查询对应设备类
|
* @param deviceTypes
|
* @return
|
*/
|
@Override
|
public Result<?> getByDeviceType(List<DeviceType> deviceTypes){
|
return Result.OK(null);
|
}
|
|
/**
|
* 通过车间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 Result<?> 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 Result.OK(list);
|
}
|
}
|