| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.google.gson.JsonSyntaxException; |
| | | import com.whyc.dto.A200ResDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.ResultA200Dto; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestClientException; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Autowired(required = false) |
| | | private DevInfMapper dinfMapper; |
| | | |
| | | @Resource |
| | | private RestTemplate restTemplate; |
| | | private final RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | public DevA200TestparamService(RestTemplate restTemplate) { |
| | | this.restTemplate = restTemplate; |
| | | } |
| | | //批量处理发送接口请求 |
| | | public ResultA200Dto getA200Dto(String url){ |
| | | ResultA200Dto dto= null; |
| | | String results =null; |
| | | try { |
| | | results = restTemplate.postForObject(url, null, String.class); |
| | | } catch (RestClientException e) { |
| | | results=" {\n" + |
| | | " \"code\": \"205\",\n" + |
| | | " \"msg\": \"接口调用出错\",\n" + |
| | | " \"data\": null,\n" + |
| | | " \"count\": 0\n" + |
| | | " }"; |
| | | }finally { |
| | | dto = ActionUtil.getGson().fromJson(results, ResultA200Dto.class); |
| | | } |
| | | return dto; |
| | | } |
| | | //读取a200一体机参数 |
| | | public Object getA200Param(int devId) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | |
| | | 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); |
| | | ResultA200Dto dto= ActionUtil.getGson().fromJson(results, ResultA200Dto.class); |
| | | ResultA200Dto dto= getA200Dto(url); |
| | | if(dto.getCode().equals("200")){ |
| | | DevA200Testparam a200Param=new DevA200Testparam(); |
| | | copyA200DTO(dto.getData(),a200Param); |
| | |
| | | String url="http://"+dinf.getDevIp()+":8080/webService/startTest"; |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>(); |
| | | paramMap.add("testType",type); |
| | | paramMap.add("testType",type);//1 放电,2 充电 |
| | | ResultA200Dto dto= (ResultA200Dto) TestparamHttpUtil.postforform_dataA200(restTemplate,url,paramMap); |
| | | return dto; |
| | | } |
| | | //a200一体机暂停/继续 |
| | | public Object pauseA200Param(int devId, int type) { |
| | | 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/pauseTest"; |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>(); |
| | | paramMap.add("controlType",type);//1 暂停测试 ,2继续测试 |
| | | ResultA200Dto dto= (ResultA200Dto) TestparamHttpUtil.postforform_dataA200(restTemplate,url,paramMap); |
| | | return dto; |
| | | } |
| | |
| | | wrapper.last("limit 1"); |
| | | DevInf dinf=dinfMapper.selectOne(wrapper); |
| | | String url="http://"+dinf.getDevIp()+":8080/webService/stopTest"; |
| | | String results = restTemplate.postForObject(url, null, String.class); |
| | | ResultA200Dto dto= ActionUtil.getGson().fromJson(results, ResultA200Dto.class); |
| | | ResultA200Dto dto= getA200Dto(url); |
| | | return dto; |
| | | } |
| | | |
| | |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | for (int devId:devIds) { |
| | | ResultA200Dto dto= (ResultA200Dto) startA200Param(devId,type); |
| | | if(dto.getCode().equals("200")){ |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("dev_id",devId); |
| | | wrapper.set("batch_state",1); |
| | | dinfMapper.update(null,wrapper); |
| | | } |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("dev_id",devId); |
| | | wrapper.set("batch_state",1); |
| | | dinfMapper.update(null,wrapper); |
| | | map.put(devId,dto); |
| | | } |
| | | return new Response().setII(1,true,map,"批量控制a200一体机"); |
| | |
| | | map.put(devId,dto); |
| | | } |
| | | return new Response().setII(1,true,map,"批量停止a200一体机"); |
| | | } |
| | | |
| | | //批量暂停/继续启动a200一体机 |
| | | public Response pauseA200ParamPl(List<Integer> devIds,int type) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | for (int devId:devIds) { |
| | | ResultA200Dto dto= (ResultA200Dto) pauseA200Param(devId,type); |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("dev_id",devId); |
| | | wrapper.set("batch_state",1); |
| | | dinfMapper.update(null,wrapper); |
| | | map.put(devId,dto); |
| | | } |
| | | return new Response().setII(1,true,map,"批量控制a200一体机"); |
| | | } |
| | | |
| | | //将dto拷贝至param |
| | |
| | | a200Param.setChargePower(dto.getChargePower()); |
| | | a200Param.setBatteryTemperatureProtect(dto.getBatteryTemperatureProtect()); |
| | | } |
| | | |
| | | |
| | | } |