| | |
| | | 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.ActmResDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.ResultActmDto; |
| | | import com.whyc.dto.*; |
| | | import com.whyc.factory.ThreadPoolExecutorFactory; |
| | | import com.whyc.mapper.DevActmTestparamMapper; |
| | | import com.whyc.mapper.DevInfMapper; |
| | | import com.whyc.pojo.db_lithium_ram_db.DevActmTestparam; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.CountDownLatch; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | |
| | | @Service |
| | |
| | | private RestTemplate restTemplate; |
| | | |
| | | //读取Actm一体机参数 |
| | | public Object getActmParam(int devId) { |
| | | public Object getActmParam(int devId,int index) { |
| | | 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); |
| | | ResultActmDto dto= ActionUtil.getGson().fromJson(results, ResultActmDto.class); |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>(); |
| | | paramMap.add("batteryStorageIndex",index); |
| | | ResultActmDto dto= (ResultActmDto) TestparamHttpUtil.postforform_dataActm(restTemplate,url,paramMap); |
| | | if(dto.getCode().equals("200")){ |
| | | DevActmTestparam actmParam=new DevActmTestparam(); |
| | | copyActmDTO(dto.getData(),actmParam); |
| | |
| | | |
| | | |
| | | //设置Actm均衡仪参数 |
| | | public Object setActmParam(ActmResDto param, int devId) { |
| | | public Object setActmParam(ActmResDto param) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("dev_id",devId); |
| | | wrapper.eq("dev_id",param.getDevId()); |
| | | wrapper.last("limit 1"); |
| | | DevInf dinf=dinfMapper.selectOne(wrapper); |
| | | String url="http://"+dinf.getDevIp()+":8080/webService/setTestParameter"; |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>(); |
| | | String paramJson= JSONObject.toJSONString(param); |
| | | paramMap.add("testParameter",paramJson); |
| | | ResultActmDto dto= (ResultActmDto) TestparamHttpUtil.postforform_data(restTemplate,url,paramMap); |
| | | paramMap.add("batteryStorageIndex",param.getBatteryStorageIndex()); |
| | | paramMap.add("moduleCode",param.getModuleCode()); |
| | | paramMap.add("workMode",param.getWorkMode()); |
| | | paramMap.add("batteryType",param.getBatteryType()); |
| | | paramMap.add("batteryNumber",param.getBatteryNumber()); |
| | | paramMap.add("ntcCount",param.getNtcCount()); |
| | | paramMap.add("testBatteryArray",param.getTestBatteryArray()); |
| | | paramMap.add("voltage",param.getVoltage()); |
| | | paramMap.add("current",param.getCurrent()); |
| | | ResultActmDto dto= (ResultActmDto) TestparamHttpUtil.postforform_dataActm(restTemplate,url,paramMap); |
| | | return dto; |
| | | } |
| | | |
| | | //批量设置Actm均衡仪参数 |
| | | public Object setActmParamPl2(ActmResDto param) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | int size=param.getDevIds().size(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(size); |
| | | for (Integer devId:param.getDevIds()) { |
| | | poolExecutor.execute(() -> { |
| | | param.setDevId(devId); |
| | | ResultActmDto dto= (ResultActmDto) setActmParam(param); |
| | | map.put(devId,dto); |
| | | latch.countDown(); |
| | | }); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return new Response().setII(1,true,map,"批量设置Actm均衡仪参数"); |
| | | } |
| | | |
| | | //批量设置Actm均衡仪参数 |
| | | public Object setActmParamPl(ActmResDto param) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | int size=param.getDevIds().size(); |
| | | for (Integer devId:param.getDevIds()) { |
| | | param.setDevId(devId); |
| | | ResultActmDto dto= (ResultActmDto) setActmParam(param); |
| | | map.put(devId,dto); |
| | | } |
| | | return new Response().setII(1,true,map,"批量设置Actm均衡仪参数"); |
| | | } |
| | | |
| | | |
| | | //启动,暂停,继续,停止actm均衡仪 |
| | | public Object controllerActmParam(int devId,int index,int type) { |
| | |
| | | case 4:url=url+"/stopTest";break; //停止 |
| | | } |
| | | paramMap.add("batteryStorageIndex",index); |
| | | ResultActmDto dto= (ResultActmDto) TestparamHttpUtil.postforform_data(restTemplate,url,paramMap); |
| | | ResultActmDto dto= (ResultActmDto) TestparamHttpUtil.postforform_dataActm(restTemplate,url,paramMap); |
| | | return dto; |
| | | } |
| | | |
| | | |
| | | //批量控制Actm均衡仪 |
| | | public Response controllActmParamPl(List<Integer> devIds) { |
| | | return new Response().set(1,true,"批量控制Actm均衡仪"); |
| | | public Response controllActmParamPl2(List<ActmPlContDto> actmPlContDtos) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(actmPlContDtos.size()); |
| | | for (ActmPlContDto actmPlContDto:actmPlContDtos) { |
| | | poolExecutor.execute(() -> { |
| | | ResultActmDto dto= (ResultActmDto) controllerActmParam(actmPlContDto.getDevId(),actmPlContDto.getIndex(),actmPlContDto.getType()); |
| | | map.put(actmPlContDto.getDevId(),dto); |
| | | latch.countDown(); |
| | | }); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return new Response().set(1,true,"批量设置Actm均衡仪参数"); |
| | | } |
| | | |
| | | //批量控制Actm均衡仪 |
| | | public Response controllActmParamPl(List<Integer> devIds, int index, int type) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | for (Integer devId:devIds) { |
| | | ResultActmDto dto= (ResultActmDto) controllerActmParam(devId,index,type); |
| | | if(type==1){ |
| | | 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,"批量设置Actm均衡仪参数"); |
| | | } |
| | | |
| | | //将dto拷贝至param |