yangys
2025-11-21 e8ed1a91c77ab62a924f12acd55777f227bacd7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.qianwen.smartman.modules.smis.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.smis.entity.WorkstationWcsUsage;
import com.qianwen.smartman.modules.smis.mapper.WorkstationWcsUsageMapper;
import com.qianwen.smartman.modules.smis.service.IWorkstationWcsUsageService;
import com.qianwen.smartman.modules.smis.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
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 super.getById(id);
    }
 
    @Override
    @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(WorkstationWcsUsage::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 
    @Transactional
    @CacheEvict(cacheNames = {WORKSTATION_WCS_USAGE_EXP}, allEntries = true)
    public Boolean save(final WorkstationWcsUsageVO workstationWcsVO) {
        Assert.isNull(workstationWcsVO.getId());
        Assert.isTrue(list(Lambda.eq(WorkstationWcsUsage::getUsageName, workstationWcsVO.getUsageName())).size() == 0, MessageUtils.message("workstation.wcs.usage.usageName.exists", new Object[0]), new Object[0]);
        Assert.isTrue(list(Lambda.eq(WorkstationWcsUsage::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 
    @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(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 
    @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]);
        }
    }
}