whyclxw
2024-09-02 6fb5bf49f4a71edf93e034a84d52f8a6eb363c4b
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
package com.whyc.service;
 
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.whyc.dto.A200ResDto;
import com.whyc.dto.Response;
import com.whyc.dto.ResultDto;
import com.whyc.mapper.DevA200TestparamMapper;
import com.whyc.mapper.DevInfMapper;
import com.whyc.pojo.db_lithium_ram_db.DevA200Testparam;
import com.whyc.pojo.db_lithium_ram_db.DevActmTestparam;
import com.whyc.pojo.db_lithium_ram_db.DevInf;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service
public class DevA200TestparamService {
    @Autowired(required = false)
    private DevA200TestparamMapper mapper;
 
    @Autowired(required = false)
    private DevInfMapper dinfMapper;
 
    @Resource
    private RestTemplate restTemplate;
 
    //读取a200一体机参数
    public Object getA200Param(int devId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("dev_id",devId);
        wrapper.last("limit 1");
        DevInf dinf=dinfMapper.selectOne(wrapper);
        String url="http://"+dinf.getDevIp()+":8080/webService/getTestParameter";
        String results = restTemplate.postForObject(url, null, String.class);
        ResultDto dto= ActionUtil.getGson().fromJson(results,ResultDto.class);
        if(dto.getCode().equals("200")){
            DevA200Testparam a200Param=new DevA200Testparam();
            copyA200DTO(dto.getData(),a200Param);
            a200Param.setDevId(devId);
            a200Param.setReturnCode(Integer.parseInt(dto.getCode()));
            UpdateWrapper updateWrapper=new UpdateWrapper();
            updateWrapper.eq("dev_id",devId);
            mapper.update(a200Param,updateWrapper);
        }
        //System.out.println(results);
         /*ResultDto dto= JSONObject.parseObject(results,ResultDto.class);
        A200ResDto a200= JSONObject.parseObject(dto.getData().toString(),A200ResDto.class);*/
        //System.out.println(dto.toString());
        return dto;
    }
 
 
    //设置a200均衡仪参数
    public Response setA200Param(DevActmTestparam param) {
        return new Response().set(1,true,"设置a200均衡仪参数");
    }
 
    //控制a200均衡仪
    public Response controllA200Param(int devId) {
        return new Response().set(1,true,"控制a200均衡仪");
    }
    //批量控制a200均衡仪
    public Response controllA200ParamPl(List<Integer> devIds) {
        return new Response().set(1,true,"批量控制a200均衡仪");
    }
 
    //将dto拷贝至param
    private void copyA200DTO(Object data, DevA200Testparam a200Param) {
        A200ResDto dto= (A200ResDto) data;
        a200Param.setBatteryName(dto.getBatteryName());
        a200Param.setNominalCapacity(dto.getNominalCapacity());
        a200Param.setBatteryType(dto.getBatteryType());
        a200Param.setBatteryNumber(dto.getBatteryNumber());
        a200Param.setDiffBatteryVoltage(dto.getDiffBatteryVoltage());
        a200Param.setDischargeCurrent(dto.getDischargeCurrent());
        a200Param.setDischargeVoltage(dto.getDischargeVoltage());
        a200Param.setDischargeTime(dto.getDischargeTime());
        a200Param.setDischargeCapacity(dto.getDischargeCapacity());
        if(dto.isDischargeCapacityEnable()){
            a200Param.setIsDischargeCapacityEnable(1);
        }else{
            a200Param.setIsDischargeCapacityEnable(0);
        }
        a200Param.setMinBatteryVoltage(dto.getMinBatteryVoltage());
        if(dto.isMinBatteryVoltageEnable()){
            a200Param.setIsMinBatteryVoltageEnable(1);
        }else{
            a200Param.setIsMinBatteryVoltageEnable(0);
        }
        a200Param.setChargeVoltage(dto.getChargeVoltage());
        a200Param.setChargeProtectVoltage(dto.getChargeProtectVoltage());
        a200Param.setChargeCurrent(dto.getChargeCurrent());
        a200Param.setChargeStopCurrent(dto.getChargeStopCurrent());
        a200Param.setChargeTime(dto.getChargeTime());
        a200Param.setChargeCapacity(dto.getChargeCapacity());
        if(dto.isChargeCapacityEnable()){
            a200Param.setIsChargeCapacityEnable(1);
        }else{
            a200Param.setIsChargeCapacityEnable(0);
        }
 
        a200Param.setMaxBatteryVoltage(dto.getMaxBatteryVoltage());
        if(dto.isMaxBatteryVoltageEnable()){
            a200Param.setIsMaxBatteryVoltageEnable(1);
        }else{
            a200Param.setIsMaxBatteryVoltageEnable(0);
        }
        a200Param.setChargePower(dto.getChargePower());
        a200Param.setBatteryTemperatureProtect(dto.getBatteryTemperatureProtect());
    }
}