|
@@ -3,18 +3,26 @@ package com.bz.smart_city.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.bz.smart_city.commom.model.CommonQueryCondition;
|
|
|
+import com.bz.smart_city.commom.util.JacksonUtil;
|
|
|
+import com.bz.smart_city.commom.util.SnowflakeIdWorker;
|
|
|
import com.bz.smart_city.commom.util.UserUtil;
|
|
|
import com.bz.smart_city.dao.MessageMapper;
|
|
|
import com.bz.smart_city.dao.MeterReadRecordMapper;
|
|
|
+import com.bz.smart_city.dao.ScRabbitConfigMapper;
|
|
|
+import com.bz.smart_city.dto.AcceptData;
|
|
|
+import com.bz.smart_city.dto.AcceptListData;
|
|
|
import com.bz.smart_city.dto.InputDeviceDto;
|
|
|
import com.bz.smart_city.dto.LoginUser;
|
|
|
import com.bz.smart_city.entity.Message;
|
|
|
import com.bz.smart_city.entity.MeterReadRecord;
|
|
|
+import com.bz.smart_city.entity.ScRabbitConfig;
|
|
|
import com.bz.smart_city.service.GdService;
|
|
|
import com.bz.smart_city.service.udip.GdAgentUtils;
|
|
|
import com.bz.smart_city.service.udip.model.GdInputDto;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.amqp.rabbit.connection.SimpleResourceHolder;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -22,10 +30,12 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
import static com.google.common.collect.Lists.newArrayList;
|
|
@@ -42,6 +52,12 @@ public class GdServiceImpl implements GdService {
|
|
|
private GdAgentUtils gdAgentUtils;
|
|
|
@Resource
|
|
|
private MessageMapper messageMapper;
|
|
|
+ @Autowired
|
|
|
+ private SnowflakeIdWorker idWorker;
|
|
|
+ @Autowired
|
|
|
+ RabbitTemplate rabbitTemplate;
|
|
|
+ @Resource
|
|
|
+ private ScRabbitConfigMapper scRabbitConfigMapper;
|
|
|
|
|
|
@Override
|
|
|
public String batchReadReal(InputDeviceDto inputDeviceDto) {
|
|
@@ -71,13 +87,14 @@ public class GdServiceImpl implements GdService {
|
|
|
}
|
|
|
}
|
|
|
if(success.get() > 0){
|
|
|
- GdInputDto gdInputDto= new GdInputDto();
|
|
|
+ /*GdInputDto gdInputDto= new GdInputDto();
|
|
|
gdInputDto.setSiteId(loginUser.getSiteId());
|
|
|
gdInputDto.setUserId(loginUser.getId());
|
|
|
gdInputDto.setType(2);
|
|
|
gdInputDto.setMap(map);
|
|
|
System.out.println(JSON.toJSONString(gdInputDto));
|
|
|
- gdAgentUtils.batchReadReal(gdInputDto);
|
|
|
+ gdAgentUtils.batchReadReal(gdInputDto);*/
|
|
|
+ sendMsg(loginUser.getSiteId(),loginUser.getId(),2, map);
|
|
|
}else {
|
|
|
Message message = new Message();
|
|
|
message.setSiteId(loginUser.getSiteId());
|
|
@@ -93,7 +110,7 @@ public class GdServiceImpl implements GdService {
|
|
|
message.setUpdateBy("system");
|
|
|
messageMapper.insertSelective(message);
|
|
|
}
|
|
|
- log.info("end allReadFreeze success={},fail={}",success.get(),fail.get());
|
|
|
+ log.info("end batchReadReal success={},fail={}",success.get(),fail.get());
|
|
|
if(fail.get() > 0){
|
|
|
return "您选择表有"+fail.get()+"只正在执行操作,仅对剩下的"+success.get()+"只进行点抄。请稍后在消息查看结果,通过刷新页面查看设备最新抄表数。";
|
|
|
}else {
|
|
@@ -146,12 +163,13 @@ public class GdServiceImpl implements GdService {
|
|
|
}
|
|
|
if(success.get() > 0){
|
|
|
GdInputDto gdInputDto= new GdInputDto();
|
|
|
- gdInputDto.setSiteId(loginUser.getSiteId());
|
|
|
+ /*gdInputDto.setSiteId(loginUser.getSiteId());
|
|
|
gdInputDto.setUserId(loginUser.getId());
|
|
|
- gdInputDto.setType(1);
|
|
|
- gdInputDto.setMap(map);
|
|
|
+ gdInputDto.setType(1);*/
|
|
|
+ /*gdInputDto.setMap(map);
|
|
|
System.out.println(JSON.toJSONString(gdInputDto));
|
|
|
- gdAgentUtils.batchReadFreeze(gdInputDto);
|
|
|
+ gdAgentUtils.batchReadFreeze(gdInputDto);*/
|
|
|
+ sendMsg(loginUser.getSiteId(),loginUser.getId(),1, map);
|
|
|
}else {
|
|
|
Message message = new Message();
|
|
|
message.setSiteId(loginUser.getSiteId());
|
|
@@ -167,7 +185,7 @@ public class GdServiceImpl implements GdService {
|
|
|
message.setUpdateBy("system");
|
|
|
messageMapper.insertSelective(message);
|
|
|
}
|
|
|
- log.info("end allReadFreeze success={},fail={},complete={}",success.get(),fail.get(),complete.get());
|
|
|
+ log.info("end batchReadFreeze success={},fail={},complete={}",success.get(),fail.get(),complete.get());
|
|
|
if(fail.get() > 0){
|
|
|
return "您选择表有"+fail.get()+"只正在执行操作,仅对剩下的"+success.get()+"只进行补抄。请稍后在消息查看结果,通过刷新页面查看设备最新抄表数。";
|
|
|
}else {
|
|
@@ -214,13 +232,14 @@ public class GdServiceImpl implements GdService {
|
|
|
}
|
|
|
}
|
|
|
if(success.get() > 0){
|
|
|
- GdInputDto gdInputDto= new GdInputDto();
|
|
|
+ /*GdInputDto gdInputDto= new GdInputDto();
|
|
|
gdInputDto.setSiteId(condition.getSiteId());
|
|
|
gdInputDto.setUserId(condition.getUserId());
|
|
|
gdInputDto.setType(4);
|
|
|
gdInputDto.setMap(map);
|
|
|
System.out.println(JSON.toJSONString(gdInputDto));
|
|
|
- gdAgentUtils.batchReadReal(gdInputDto);
|
|
|
+ gdAgentUtils.batchReadReal(gdInputDto);*/
|
|
|
+ sendMsg(condition.getSiteId(),condition.getUserId(),4, map);
|
|
|
}else {
|
|
|
Message message = new Message();
|
|
|
message.setSiteId(condition.getSiteId());
|
|
@@ -236,7 +255,7 @@ public class GdServiceImpl implements GdService {
|
|
|
message.setUpdateBy("system");
|
|
|
messageMapper.insertSelective(message);
|
|
|
}
|
|
|
- log.info("end allReadFreeze success={},fail={}",success.get(),fail.get());
|
|
|
+ log.info("end allReadReal success={},fail={}",success.get(),fail.get());
|
|
|
if(fail.get() > 0){
|
|
|
return "您选择表有"+fail.get()+"只正在执行操作,仅对剩下的"+success.get()+"只进行点抄。请稍后在消息查看结果,通过刷新页面查看设备最新抄表数。";
|
|
|
}else {
|
|
@@ -275,13 +294,14 @@ public class GdServiceImpl implements GdService {
|
|
|
}
|
|
|
}
|
|
|
if(success.get() > 0){
|
|
|
- GdInputDto gdInputDto= new GdInputDto();
|
|
|
+ /*GdInputDto gdInputDto= new GdInputDto();
|
|
|
gdInputDto.setSiteId(condition.getSiteId());
|
|
|
gdInputDto.setUserId(condition.getUserId());
|
|
|
gdInputDto.setType(3);
|
|
|
gdInputDto.setMap(map);
|
|
|
System.out.println(JSON.toJSONString(gdInputDto));
|
|
|
- gdAgentUtils.batchReadFreeze(gdInputDto);
|
|
|
+ gdAgentUtils.batchReadFreeze(gdInputDto);*/
|
|
|
+ sendMsg(condition.getSiteId(),condition.getUserId(),3, map);
|
|
|
}else {
|
|
|
Message message = new Message();
|
|
|
message.setSiteId(condition.getSiteId());
|
|
@@ -317,4 +337,72 @@ public class GdServiceImpl implements GdService {
|
|
|
if(type == 4) return "全部补抄";
|
|
|
return "";
|
|
|
}
|
|
|
+
|
|
|
+ private void sendMsg(Integer siteId,Integer userId,Integer type,Map<String,List<String>> map){
|
|
|
+ List<Map<String,List<String>>> list = newArrayList();
|
|
|
+ if (map != null) {
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ List<String> deviceIdStrList = map.get(key);
|
|
|
+ // 分批
|
|
|
+ if (deviceIdStrList != null && deviceIdStrList.size() > 0) {
|
|
|
+ int total = deviceIdStrList.size();
|
|
|
+ int pageSize = 5;
|
|
|
+ int totalPage = total / pageSize;
|
|
|
+ if (total % pageSize != 0) {
|
|
|
+ totalPage++;
|
|
|
+ }
|
|
|
+ for (int i = 1; i <= totalPage; i++)
|
|
|
+ {
|
|
|
+ log.info("current page = " + i);
|
|
|
+ List<String> records = newArrayList();
|
|
|
+ int start = (i - 1) * pageSize;
|
|
|
+ int j = 0;
|
|
|
+
|
|
|
+ for (int index = 0; (j < pageSize) && (index < total); j++)
|
|
|
+ {
|
|
|
+ index = start + j;
|
|
|
+ records.add(deviceIdStrList.get(index));
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String,List<String>> tempMap = new HashMap<>();
|
|
|
+ tempMap.put(key,records);
|
|
|
+ list.add(tempMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("current list size = " + list.size());
|
|
|
+ //保存redis
|
|
|
+ Long id = idWorker.nextId();
|
|
|
+ Map<String,Object> redisMap = new HashMap<>();
|
|
|
+ redisMap.put("siteId",siteId);
|
|
|
+ redisMap.put("userId",userId);
|
|
|
+ redisMap.put("type",type);
|
|
|
+ redisMap.put("size",list.size());
|
|
|
+ redisMap.put("complete",0);
|
|
|
+ redisMap.put("success",0);
|
|
|
+ redisMap.put("fail",0);
|
|
|
+ redisTemplate.opsForHash().putAll("GdReadingTask:"+id,redisMap);
|
|
|
+ redisTemplate.expire("GdReadingTask:"+id,86400, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ ScRabbitConfig config = scRabbitConfigMapper.findByCode("gd-read-meter");
|
|
|
+
|
|
|
+ for (Map<String, List<String>> stringListMap : list) {
|
|
|
+
|
|
|
+ GdInputDto gdInputDto= new GdInputDto();
|
|
|
+ gdInputDto.setTaskId(id.toString());
|
|
|
+ gdInputDto.setMap(stringListMap);
|
|
|
+ //发送消息
|
|
|
+ //设置当前线程lookupKey,内部由ThreadLocal实现
|
|
|
+ SimpleResourceHolder.bind(rabbitTemplate.getConnectionFactory(), config.getCode());
|
|
|
+ //业务操作会根据线程中的lookupKey从routeConnectionFactory的targetConnectionFactories中选择对应的connectionFactory
|
|
|
+ String msg = JSON.toJSONString(gdInputDto);
|
|
|
+ System.out.println(msg);
|
|
|
+ rabbitTemplate.convertAndSend(config.getExchange(),config.getRoutingKey(), msg.getBytes(Charset.forName("UTF-8")));
|
|
|
+ //操作完以后记得解绑。不影响线程的后序其他工厂操作
|
|
|
+ SimpleResourceHolder.unbind(rabbitTemplate.getConnectionFactory());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|