package com.qianwen.smartman.modules.andon.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
import com.google.common.collect.Lists;
|
import java.lang.invoke.SerializedLambda;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
import com.qianwen.smartman.common.cache.RegionCache;
|
import com.qianwen.smartman.common.utils.Lambda;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.andon.convert.AndonTypeConvert;
|
import com.qianwen.smartman.modules.andon.entity.AndonRecord;
|
import com.qianwen.smartman.modules.andon.entity.AndonType;
|
import com.qianwen.smartman.modules.andon.entity.DeviceAndonType;
|
import com.qianwen.smartman.modules.andon.enums.AndonStatusEnum;
|
import com.qianwen.smartman.modules.andon.mapper.AndonTypeMapper;
|
import com.qianwen.smartman.modules.andon.service.IAndonRecordService;
|
import com.qianwen.smartman.modules.andon.service.IAndonTypeService;
|
import com.qianwen.smartman.modules.andon.service.IDeviceAndonTypeService;
|
import com.qianwen.smartman.modules.andon.vo.AndonTypeDetailVO;
|
import com.qianwen.smartman.modules.andon.vo.AndonTypeSaveVO;
|
import com.qianwen.smartman.modules.andon.vo.AndonTypeUpdateVO;
|
import com.qianwen.smartman.modules.andon.vo.AndonTypeVO;
|
import com.qianwen.smartman.modules.andon.vo.BindingDeviceTypeVO;
|
import com.qianwen.smartman.modules.system.service.ICodeGeneratorService;
|
import com.qianwen.smartman.modules.tpm.enums.MetaTypeEnum;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/andon/service/impl/AndonTypeServiceImpl.class */
|
public class AndonTypeServiceImpl extends BladeServiceImpl<AndonTypeMapper, AndonType> implements IAndonTypeService {
|
private final ICodeGeneratorService codeGeneratorService;
|
private final IDeviceAndonTypeService deviceAndonTypeService;
|
private final IAndonRecordService recordService;
|
|
public AndonTypeServiceImpl(final ICodeGeneratorService codeGeneratorService, final IDeviceAndonTypeService deviceAndonTypeService, final IAndonRecordService recordService) {
|
this.codeGeneratorService = codeGeneratorService;
|
this.deviceAndonTypeService = deviceAndonTypeService;
|
this.recordService = recordService;
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonTypeService
|
@Transactional(rollbackFor = {Exception.class})
|
public AndonTypeVO saveAndonType(AndonTypeSaveVO vo) {
|
andonTypeCodeGenerator(vo);
|
checkDuplicateCode(vo.getCode());
|
AndonType type = new AndonType().setCode(vo.getCode()).setName(vo.getName()).setRemark(vo.getRemark());
|
save(type);
|
saveDeviceTypeBinding(type.getId(), vo.getDeviceTypeIds());
|
return AndonTypeConvert.INSTANCE.convert(type);
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonTypeService
|
@Transactional(rollbackFor = {Exception.class})
|
public Boolean updateAndonType(AndonTypeUpdateVO vo) {
|
Long typeId = vo.getId();
|
notUpdate(typeId);
|
boolean update = Lambda.updateWrapper(this.baseMapper).set(AndonType::getName, vo.getName()).set(AndonType::getRemark, vo.getRemark()).eq(AndonType::getId, typeId).update();
|
List<AndonRecord> list = this.recordService.list(Lambda.eq(AndonRecord::getTypeId, typeId)
|
.in(AndonRecord::getCurStatus, Lists.newArrayList(new Integer[] { AndonStatusEnum.ALREADY_RECEIVED.getStatus(), AndonStatusEnum.HAVA_INITIATED.getStatus() })));
|
List<Long> deviceTypeIds = vo.getDeviceTypeIds();
|
if (Func.isNotEmpty(list)) {
|
List<DeviceAndonType> typeList = this.deviceAndonTypeService.list(Lambda.eq(DeviceAndonType::getAndonTypeId, typeId));
|
List<Long> collect = (List<Long>)typeList.stream().map(DeviceAndonType::getDeviceTypeId).collect(Collectors.toList());
|
boolean sameList = sameList(collect, deviceTypeIds);
|
if (sameList)
|
throw new ServiceException(MessageUtils.message("andon.type.device.type.update", new Object[0]));
|
}
|
update = (this.deviceAndonTypeService.remove(Lambda.eq(DeviceAndonType::getAndonTypeId, typeId)) && update);
|
saveDeviceTypeBinding(typeId, deviceTypeIds);
|
return Boolean.valueOf(update);
|
|
/*
|
Long typeId = vo.getId();
|
notUpdate(typeId);
|
boolean update = ((LambdaUpdateChainWrapper) ((LambdaUpdateChainWrapper) ((LambdaUpdateChainWrapper) Lambda.updateWrapper(this.baseMapper).set((v0) -> {
|
return v0.getName();
|
}, vo.getName())).set((v0) -> {
|
return v0.getRemark();
|
}, vo.getRemark())).eq((v0) -> {
|
return v0.getId();
|
}, typeId)).update();
|
List<AndonRecord> list = this.recordService.list((Wrapper) Lambda.eq((v0) -> {
|
return v0.getTypeId();
|
}, typeId).in((v0) -> {
|
return v0.getCurStatus();
|
}, Lists.newArrayList(new Integer[]{AndonStatusEnum.ALREADY_RECEIVED.getStatus(), AndonStatusEnum.HAVA_INITIATED.getStatus()})));
|
List<Long> deviceTypeIds = vo.getDeviceTypeIds();
|
if (Func.isNotEmpty(list)) {
|
List<DeviceAndonType> typeList = this.deviceAndonTypeService.list(Lambda.eq((v0) -> {
|
return v0.getAndonTypeId();
|
}, typeId));
|
List<Long> collect = (List) typeList.stream().map((v0) -> {
|
return v0.getDeviceTypeId();
|
}).collect(Collectors.toList());
|
boolean sameList = sameList(collect, deviceTypeIds);
|
if (sameList) {
|
throw new ServiceException(MessageUtils.message("andon.type.device.type.update", new Object[0]));
|
}
|
}
|
boolean update2 = this.deviceAndonTypeService.remove(Lambda.eq((v0) -> {
|
return v0.getAndonTypeId();
|
}, typeId)) && update;
|
saveDeviceTypeBinding(typeId, deviceTypeIds);
|
return Boolean.valueOf(update2);
|
*/
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonTypeService
|
public Boolean removeAndonType(Long typeId) {
|
notRemove(typeId);
|
return Boolean.valueOf(removeById(typeId));
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonTypeService
|
public List<AndonTypeVO> andonTypeList(String keyword) {
|
return this.baseMapper.andonTypeList(keyword);
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonTypeService
|
public AndonTypeDetailVO detail(Long typeId) {
|
return this.baseMapper.detail(typeId);
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonTypeService
|
public List<BindingDeviceTypeVO> allDeviceTypes(String typeId) {
|
return this.baseMapper.allDeviceTypes(typeId);
|
}
|
|
@Override // org.springblade.modules.andon.service.IAndonTypeService
|
public List<AndonTypeVO> workBanding(Long workstationId) {
|
return this.baseMapper.workBanding(workstationId);
|
}
|
|
private boolean sameList(List<Long> l1, List<Long> l2) {
|
if (l1.size() != l2.size()) {
|
return true;
|
}
|
String c1 = (String) l1.stream().sorted((v0, v1) -> {
|
return v0.compareTo(v1);
|
}).map((v0) -> {
|
return String.valueOf(v0);
|
}).collect(Collectors.joining(","));
|
String c2 = (String) l2.stream().sorted((v0, v1) -> {
|
return v0.compareTo(v1);
|
}).map((v0) -> {
|
return String.valueOf(v0);
|
}).collect(Collectors.joining(","));
|
return !c1.equals(c2);
|
}
|
|
private void notRemove(Long typeId) {
|
List<AndonRecord> list = this.recordService.list(Lambda.eq((v0) -> {
|
return v0.getTypeId();
|
}, typeId));
|
if (Func.isNotEmpty(list)) {
|
throw new ServiceException(MessageUtils.message("andon.type.has.record", new Object[0]));
|
}
|
}
|
|
private void notUpdate(Long typeId) {
|
List<AndonRecord> list = this.recordService.list(Lambda.eq(AndonRecord::getTypeId, typeId).in(AndonRecord::getCurStatus,
|
Lists.newArrayList(AndonStatusEnum.ALREADY_RECEIVED.getStatus(), AndonStatusEnum.HAVA_INITIATED.getStatus())));
|
if (Func.isNotEmpty(list))
|
throw new ServiceException(MessageUtils.message("andon.type.not.update", new Object[0]));
|
/*
|
List<AndonRecord> list = this.recordService.list((Wrapper) Lambda.eq((v0) -> {
|
return v0.getTypeId();
|
}, typeId).in((v0) -> {
|
return v0.getCurStatus();
|
}, Lists.newArrayList(new Integer[]{AndonStatusEnum.ALREADY_RECEIVED.getStatus(), AndonStatusEnum.HAVA_INITIATED.getStatus()})));
|
if (Func.isNotEmpty(list)) {
|
throw new ServiceException(MessageUtils.message("andon.type.not.update", new Object[0]));
|
}
|
*/
|
}
|
|
private void saveDeviceTypeBinding(Long andonTypeId, List<Long> deviceTypeIds) {
|
List<DeviceAndonType> types = deviceTypeIds.stream().map(dt -> {
|
return new DeviceAndonType().setAndonTypeId(andonTypeId).setDeviceTypeId(dt);
|
}).collect(Collectors.toList());
|
this.deviceAndonTypeService.saveBatch(types);
|
}
|
|
private void andonTypeCodeGenerator(AndonTypeSaveVO vo) {
|
if (Func.isBlank(vo.getCode())) {
|
String code = this.codeGeneratorService.getGeneratorCode(vo, MetaTypeEnum.ANDON_TYPE.getCode());
|
if (Func.isBlank(code)) {
|
throw new ServiceException(MessageUtils.message("cps.tpm.maintain.coding.rules", new Object[0]));
|
}
|
vo.setCode(code);
|
}
|
}
|
|
private void checkDuplicateCode(String code) {
|
List<AndonType> list = list(Lambda.eq(AndonType::getCode, code));
|
|
if (Func.isNotEmpty(list)) {
|
throw new ServiceException(MessageUtils.message("andon.type.code.dub", new Object[0]));
|
}
|
}
|
}
|