package com.qianwen.smartman.modules.cps.service.impl;
|
|
import java.io.Serializable;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.function.Function;
|
import java.util.stream.Collectors;
|
|
import javax.validation.constraints.NotNull;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.common.constant.DictConstant;
|
import com.qianwen.smartman.common.utils.Lambda;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.smartman.modules.cps.entity.WorkstationWcsUsage;
|
import com.qianwen.smartman.modules.cps.mapper.WorkstationWcsUsageMapper;
|
import com.qianwen.smartman.modules.cps.service.IWorkstationWcsUsageService;
|
import com.qianwen.smartman.modules.cps.vo.WorkstationWcsUsageVO;
|
import com.qianwen.smartman.modules.system.service.IDictService;
|
import com.qianwen.smartman.modules.tdengine.service.IWorkstationDynamicCollectService;
|
|
import cn.hutool.core.lang.Assert;
|
import cn.hutool.json.JSONUtil;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/WorkstationWcsUsageServiceImpl.class */
|
public class WorkstationWcsUsageServiceImpl extends ServiceImpl<WorkstationWcsUsageMapper, WorkstationWcsUsage> implements IWorkstationWcsUsageService {
|
private static final String WORKSTATION_WCS_USAGE_EXP = "blade:wcs:usage#259200";
|
private final IDictService dictService;
|
private final IWorkstationDynamicCollectService workstationDynamicCollectService;
|
|
|
|
public WorkstationWcsUsageServiceImpl(final IDictService dictService, final IWorkstationDynamicCollectService workstationDynamicCollectService) {
|
this.dictService = dictService;
|
this.workstationDynamicCollectService = workstationDynamicCollectService;
|
}
|
|
@Cacheable(cacheNames = {WORKSTATION_WCS_USAGE_EXP}, key = "'cps:id:'.concat(#id)")
|
/* renamed from: getById */
|
public WorkstationWcsUsage m202getById(Serializable id) {
|
return (WorkstationWcsUsage) super.getById(id);
|
}
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWcsUsageService
|
@Cacheable(cacheNames = {WORKSTATION_WCS_USAGE_EXP}, key = "'usage:list'")
|
public List<WorkstationWcsUsageVO> listVO() {
|
Map<Integer, String> wcsMap = this.dictService.getList(DictConstant.WORKSTATION_PARAM_TYPE).stream().collect(Collectors.toMap(dict -> {
|
return Integer.valueOf(Func.toInt(dict.getDictKey()));
|
}, (v0) -> {
|
return v0.getDictValue();
|
}));
|
return list(Lambda.asc((v0) -> {
|
return v0.getCollectType();
|
})).stream().map(it -> {
|
WorkstationWcsUsageVO vo = new WorkstationWcsUsageVO();
|
vo.setId(Func.toStr(it.getId()));
|
vo.setCollectType(it.getCollectType());
|
vo.setUsageName(it.getUsageName());
|
vo.setUsageCode(it.getUsageCode());
|
vo.setDataTypeDesc((String) wcsMap.getOrDefault(it.getCollectType(), ""));
|
vo.setParameter(it.getParameter());
|
return vo;
|
}).collect(Collectors.toList());
|
}
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWcsUsageService
|
@Transactional
|
@CacheEvict(cacheNames = {WORKSTATION_WCS_USAGE_EXP}, allEntries = true)
|
public Boolean save(final WorkstationWcsUsageVO workstationWcsVO) {
|
Assert.isNull(workstationWcsVO.getId());
|
Assert.isTrue(list(Lambda.eq((v0) -> {
|
return v0.getUsageName();
|
}, workstationWcsVO.getUsageName())).size() == 0, MessageUtils.message("workstation.wcs.usage.usageName.exists", new Object[0]), new Object[0]);
|
Assert.isTrue(list(Lambda.eq((v0) -> {
|
return v0.getUsageCode();
|
}, workstationWcsVO.getUsageCode())).size() == 0, MessageUtils.message("workstation.wcs.usage.usageCode.exists", new Object[0]), new Object[0]);
|
Assert.isTrue(Func.isEmpty(workstationWcsVO.getParameter()) || JSONUtil.isJsonObj(workstationWcsVO.getParameter()), MessageUtils.message("workstation.wcs.usage.parameter.nojson", new Object[0]), new Object[0]);
|
WorkstationWcsUsage usage = new WorkstationWcsUsage();
|
usage.setCollectType(workstationWcsVO.getCollectType());
|
usage.setUsageName(workstationWcsVO.getUsageName());
|
usage.setUsageCode(workstationWcsVO.getUsageCode());
|
usage.setParameter(workstationWcsVO.getParameter());
|
return Boolean.valueOf(save(usage));
|
}
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWcsUsageService
|
@Transactional
|
@CacheEvict(cacheNames = {WORKSTATION_WCS_USAGE_EXP}, allEntries = true)
|
public Boolean update(final WorkstationWcsUsageVO workstationWcsVO) {
|
Assert.notNull(workstationWcsVO.getId());
|
|
Assert.isTrue(
|
(list(Lambda.eq(WorkstationWcsUsage::getUsageName, workstationWcsVO.getUsageName()).ne(WorkstationWcsUsage::getId, workstationWcsVO.getId())).size() == 0),
|
MessageUtils.message("workstation.wcs.usage.usageName.exists", new Object[0]), new Object[0]);
|
Assert.isTrue(
|
(list(Lambda.eq(WorkstationWcsUsage::getUsageCode, workstationWcsVO.getUsageCode()).ne(WorkstationWcsUsage::getId, workstationWcsVO.getId())).size() == 0),
|
MessageUtils.message("workstation.wcs.usage.usageCode.exists", new Object[0]), new Object[0]);
|
/*
|
Assert.isTrue(list((Wrapper) Lambda.eq((v0) -> {
|
return v0.getUsageName();
|
}, workstationWcsVO.getUsageName()).ne((v0) -> {
|
return v0.getId();
|
}, workstationWcsVO.getId())).size() == 0, MessageUtils.message("workstation.wcs.usage.usageName.exists", new Object[0]), new Object[0]);
|
Assert.isTrue(list((Wrapper) Lambda.eq((v0) -> {
|
return v0.getUsageCode();
|
}, workstationWcsVO.getUsageCode()).ne((v0) -> {
|
return v0.getId();
|
}, workstationWcsVO.getId())).size() == 0, MessageUtils.message("workstation.wcs.usage.usageCode.exists", new Object[0]), new Object[0]);
|
*/
|
Assert.isTrue(Func.isEmpty(workstationWcsVO.getParameter()) || JSONUtil.isJsonObj(workstationWcsVO.getParameter()), MessageUtils.message("workstation.wcs.usage.parameter.nojson", new Object[0]), new Object[0]);
|
wcsUsageUsedValid(workstationWcsVO.getId(), oldUsage -> {
|
return Boolean.valueOf((oldUsage.getUsageCode().equals(workstationWcsVO.getUsageCode()) && oldUsage.getCollectType().equals(workstationWcsVO.getCollectType()) && oldUsage.getUsageName().equals(workstationWcsVO.getUsageName())) ? false : true);
|
});
|
WorkstationWcsUsage usage = new WorkstationWcsUsage();
|
usage.setId(Long.valueOf(Func.toLong(workstationWcsVO.getId())));
|
usage.setCollectType(workstationWcsVO.getCollectType());
|
usage.setUsageName(workstationWcsVO.getUsageName());
|
usage.setUsageCode(workstationWcsVO.getUsageCode());
|
usage.setParameter(workstationWcsVO.getParameter());
|
return Boolean.valueOf(updateById(usage));
|
}
|
|
@Override // org.springblade.modules.cps.service.IWorkstationWcsUsageService
|
@Transactional
|
@CacheEvict(cacheNames = {WORKSTATION_WCS_USAGE_EXP}, allEntries = true)
|
public Boolean remove(Long usageId) {
|
wcsUsageUsedValid(usageId, (v0) -> {
|
return Objects.nonNull(v0);
|
});
|
this.workstationDynamicCollectService.removeTable(m202getById((Serializable) usageId));
|
this.workstationDynamicCollectService.getWorkstationIdsByUsageId(usageId);
|
return Boolean.valueOf(removeById(usageId));
|
}
|
|
public void wcsUsageUsedValid(@NotNull final Serializable usageId, Function<WorkstationWcsUsage, Boolean> triggerValidCondition) {
|
WorkstationWcsUsage oldUsage = m202getById(usageId);
|
if (triggerValidCondition.apply(oldUsage).booleanValue()) {
|
Assert.isTrue(this.workstationDynamicCollectService.getWorkstationIdsByUsageId(oldUsage.getId()).size() == 0, MessageUtils.message("workstation.wcs.usage.used", new Object[0]), new Object[0]);
|
}
|
}
|
}
|