whycxzp
2025-04-30 b278d488be1d5e626eecdcfc2201b97dc85937cf
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.whyc.dto.Response;
import com.whyc.mapper.AbeStateMapper;
import com.whyc.pojo.db_abe_ram.AbeState;
import com.whyc.util.ActionUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
 
@Service
public class AbeStateService {
 
    public static final int CMD_StopHuoHua_Test                         = 0x20;       //停止活化测试
    public static final int CMD_StopHuoHua_TestAck                     = 0x21;       //停止活化测试成功
 
    @Resource
    private AbeStateMapper mapper;
 
    public Response<AbeState> get() {
        QueryWrapper<AbeState> query = Wrappers.query();
        query.last(" limit 1");
        AbeState abeState = mapper.selectOne(query);
        return new Response<AbeState>().set(1,abeState);
    }
 
    public Response stopHuoHua() {
        boolean flag = sendCmdToDev(CMD_StopHuoHua_Test);
        return new Response().set(1,flag,flag?"停止活化测试成功":"停止活化测试失败");
    }
 
    public boolean sendCmdToDev(int opCmd) {
        int m_cmd = opCmd;
        int m_cmd_ack = opCmd;
        switch(m_cmd) {
            case CMD_StopHuoHua_Test: m_cmd_ack = CMD_StopHuoHua_TestAck; break;
            default:
                return false;
        }
        //更新op_cmd
        UpdateWrapper<AbeState> updateWrapper = Wrappers.update();
        updateWrapper.set("op_cmd",m_cmd);
        int flag=mapper.update((AbeState) ActionUtil.objeNull,updateWrapper);
        boolean res_exe = false;
        if(flag>0)
        {
            QueryWrapper<AbeState> queryWrapper = Wrappers.query();
            queryWrapper.last(" limit 1");
            for(int n=0; n<80; n++)
            {
 
                AbeState param=mapper.selectOne(queryWrapper);
                if(param!=null){
                    if(param.getOpCmd()==m_cmd_ack){
                        res_exe = true;
                        break;
                    }
                    try {
                        Thread.sleep(250);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else {
                    break;
                }
            }
        }
        return res_exe;
    }
}