| | |
| | | import com.whyc.dto.A200ResDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.ResultA200Dto; |
| | | import com.whyc.factory.ThreadPoolExecutorFactory; |
| | | import com.whyc.mapper.DevA200TestparamMapper; |
| | | import com.whyc.mapper.DevInfMapper; |
| | | import com.whyc.pojo.db_lithium_ram_db.DevA200Testparam; |
| | |
| | | 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 |
| | | public class DevA200TestparamService { |
| | |
| | | |
| | | |
| | | //设置a200均衡仪参数 |
| | | public Object setA200Param(A200ResDto param,int devId) { |
| | | public Object setA200Param(A200ResDto 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"; |
| | |
| | | paramMap.add("testParameter",paramJson); |
| | | ResultA200Dto dto= (ResultA200Dto) TestparamHttpUtil.postforform_data(restTemplate,url,paramMap); |
| | | return dto; |
| | | } |
| | | |
| | | //批量设置a200均衡仪参数 |
| | | public Object setA200ParamPl(List<A200ResDto> params) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(params.size()); |
| | | for (A200ResDto param:params) { |
| | | poolExecutor.execute(() -> { |
| | | ResultA200Dto dto= (ResultA200Dto) setA200Param(param); |
| | | map.put(param.getDevId(),dto); |
| | | latch.countDown(); |
| | | }); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return new Response().set(1,true,"批量控制a200均衡仪"); |
| | | } |
| | | |
| | | //启动a200均衡仪放电/充电 |
| | |
| | | return dto; |
| | | } |
| | | |
| | | //批量控制a200均衡仪 |
| | | public Response controllA200ParamPl(List<Integer> devIds) { |
| | | //批量启动a200均衡仪 |
| | | public Response startA200ParamPl(List<Integer> devIds,int type) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(devIds.size()); |
| | | for (int devId:devIds) { |
| | | poolExecutor.execute(() -> { |
| | | ResultA200Dto dto= (ResultA200Dto) startA200Param(devId,type); |
| | | map.put(devId,dto); |
| | | latch.countDown(); |
| | | }); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return new Response().set(1,true,"批量控制a200均衡仪"); |
| | | } |
| | | |
| | | //批量启动a200均衡仪 |
| | | public Response stopA200ParamPl(List<Integer> devIds) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(devIds.size()); |
| | | for (int devId:devIds) { |
| | | poolExecutor.execute(() -> { |
| | | ResultA200Dto dto= (ResultA200Dto) stopA200Param(devId); |
| | | map.put(devId,dto); |
| | | latch.countDown(); |
| | | }); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return new Response().set(1,true,"批量控制a200均衡仪"); |
| | | } |
| | | |