yangys
2024-05-07 1251cce20deab6e388b1e2ff8cdddd2896db162b
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
package com.qianwen.smartman.modules.dmpLog.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.ArrayList;
import java.util.List;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.redis.cache.BladeRedis;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.entity.Machine;
import com.qianwen.smartman.modules.cps.service.IMachineService;
import com.qianwen.smartman.modules.dmpLog.mapper.DmpLogSignalFlowMapper;
import com.qianwen.smartman.modules.dmpLog.mapper.DmpLogSignalMapper;
import com.qianwen.smartman.modules.dmpLog.service.IDmpLogService;
import com.qianwen.smartman.modules.dmpLog.vo.DmpLogDetailVO;
import com.qianwen.smartman.modules.dmpLog.vo.DmpLogSearchVO;
import com.qianwen.smartman.modules.dmpLog.vo.DmpLogVo;
import org.springframework.stereotype.Service;
 
@Service
public class DmpLogServiceImpl implements IDmpLogService {
    private final DmpLogSignalMapper dmpLogSignalMapper;
    private final DmpLogSignalFlowMapper dmpLogSignalFlowMapper;
    private final IMachineService machineService;
    private final BladeRedis bladeRedis;
    private static final String DmpLog_CACHE = "blade:dmp-log:";
    private static final String keyPrefix = ":machineId:";
 
    public DmpLogServiceImpl(final DmpLogSignalMapper dmpLogSignalMapper, final DmpLogSignalFlowMapper dmpLogSignalFlowMapper, final IMachineService machineService, final BladeRedis bladeRedis) {
        this.dmpLogSignalMapper = dmpLogSignalMapper;
        this.dmpLogSignalFlowMapper = dmpLogSignalFlowMapper;
        this.machineService = machineService;
        this.bladeRedis = bladeRedis;
    }
 
    @Override
    public IPage<DmpLogVo> pageDmpLog(DmpLogSearchVO dmpLogSearchVO, Query query) {
        List<DmpLogVo> result;
        Integer total;
        IPage<DmpLogVo> page = Condition.getPage(query);
        new ArrayList<>();
        try {
            result = this.dmpLogSignalMapper.pageDmpLog(dmpLogSearchVO, Integer.valueOf((query.getCurrent().intValue() - 1) * query.getSize().intValue()), query.getSize());
            result.forEach(item -> {
                item.setMachineCode(machineIdToMachineCode(item.getMachineCode()));
            });
            total = this.dmpLogSignalMapper.countDmpLog(dmpLogSearchVO);
        } catch (Exception e) {
            result = new ArrayList<>();
            total = 0;
        }
        page.setRecords(result);
        page.setTotal(total == null ? 0L : total.intValue());
        return page;
    }
 
    private String machineIdToMachineCode(String machineId) {
        String machineCode = (String) this.bladeRedis.get("blade:dmp-log::machineId:" + machineId);
        if (machineCode == null) {
            Machine machine = (Machine) this.machineService.getById(machineId);
            if (Func.isNull(machine)) {
                machineCode = "";
            } else {
                machineCode = machine.getMachineCode();
            }
            this.bladeRedis.setEx("blade:dmp-log::machineId:" + machineId, machineCode, 60L);
        }
        return machineCode;
    }
 
    @Override
    public List<DmpLogDetailVO> getDmpLogDetail(String traceId) {
        return this.dmpLogSignalFlowMapper.getByTraceId(traceId);
    }
}