使用天地图反查填补历史数据

This commit is contained in:
liuchengqian 2024-12-02 16:52:13 +08:00
parent ca2b4684d9
commit 6117738019

View File

@ -5,22 +5,29 @@ import com.xkrs.dao.FirePointOrdinaryDao;
import com.xkrs.dao.StreetDao;
import com.xkrs.dao.SysUserDao;
import com.xkrs.fireseason.FireSeasonConfigService;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.bean.AddressBean;
import com.xkrs.model.entity.FirePointOrdinaryEntity;
import com.xkrs.model.qo.AllFirePointQo;
import com.xkrs.model.qo.UpdateFirePointQo;
import com.xkrs.service.DispatchFirePointService;
import com.xkrs.service.impl.FirePointServiceImpl;
import com.xkrs.utilsnew.SMSUtils;
import com.xkrs.utilsnew.FirePointAddressUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.*;
import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@ -75,33 +82,74 @@ public class DispatchFirePointController {
// }
//群发短信-start
int groupCount = 50;
List<SysUserEntity> sysUserList = sysUserDao.findAll();
Map<Integer, List<SysUserEntity>> sysUserMap = new HashMap<>();
for (int i = 0; i < sysUserList.size(); i++) {
SysUserEntity sysUser = sysUserList.get(i);
int groupIndex = i / groupCount;
if (sysUserMap.containsKey(groupIndex)) {
List<SysUserEntity> groupSysUserList = sysUserMap.get(groupIndex);
groupSysUserList.add(sysUser);
} else {
List<SysUserEntity> groupSysUserList = new ArrayList<>();
groupSysUserList.add(sysUser);
sysUserMap.put(groupIndex, groupSysUserList);
}
}
for (Map.Entry<Integer, List<SysUserEntity>> entry : sysUserMap.entrySet()) {
List<SysUserEntity> smsReceiverList = entry.getValue();
String[] telephoneArray = new String[smsReceiverList.size()];
for (int i = 0; i < smsReceiverList.size(); i++) {
telephoneArray[i] = "86" + smsReceiverList.get(i).getUserName();
}
int resValue = SMSUtils.sendSmsToUser(telephoneArray, "1932636", new String[]{});
System.out.println("resValue = " + resValue);
}
// int groupCount = 50;
// List<SysUserEntity> sysUserList = sysUserDao.findAll();
// Map<Integer, List<SysUserEntity>> sysUserMap = new HashMap<>();
// for (int i = 0; i < sysUserList.size(); i++) {
// SysUserEntity sysUser = sysUserList.get(i);
// int groupIndex = i / groupCount;
// if (sysUserMap.containsKey(groupIndex)) {
// List<SysUserEntity> groupSysUserList = sysUserMap.get(groupIndex);
// groupSysUserList.add(sysUser);
// } else {
// List<SysUserEntity> groupSysUserList = new ArrayList<>();
// groupSysUserList.add(sysUser);
// sysUserMap.put(groupIndex, groupSysUserList);
// }
// }
// for (Map.Entry<Integer, List<SysUserEntity>> entry : sysUserMap.entrySet()) {
// List<SysUserEntity> smsReceiverList = entry.getValue();
// String[] telephoneArray = new String[smsReceiverList.size()];
// for (int i = 0; i < smsReceiverList.size(); i++) {
// telephoneArray[i] = "86" + smsReceiverList.get(i).getUserName();
// }
// int resValue = SMSUtils.sendSmsToUser(telephoneArray, "1932636", new String[]{});
// System.out.println("resValue = " + resValue);
// }
// int resValue = SMSUtils.sendSmsToUser(new String[]{"8615764226530"}, "1932636", new String[]{});
// System.out.println("resValue = " + resValue);
//群发短信-end
//使用天地图反查填补历史数据-start
System.out.println("开始解析");
while (true) {
//查询未审核的普通火点
Specification<FirePointOrdinaryEntity> specificationOrdinary = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
predicateList.add(criteriaBuilder.isNull(root.get("townCode").as(String.class)));
predicateList.add(criteriaBuilder.equal(root.get("townCode").as(String.class), ""));
predicateList.add(criteriaBuilder.isNull(root.get("townName").as(String.class)));
predicateList.add(criteriaBuilder.equal(root.get("townName").as(String.class), ""));
predicateList.add(criteriaBuilder.isNull(root.get("firePointAddress").as(String.class)));
predicateList.add(criteriaBuilder.equal(root.get("firePointAddress").as(String.class), ""));
return criteriaBuilder.or(predicateList.toArray(new Predicate[predicateList.size()]));
};
//未审核的普通火点列表
PageRequest pageRequest = PageRequest.of(1, 1000, Sort.by(Sort.Direction.DESC, "satelliteTime"));
List<FirePointOrdinaryEntity> list = firePointOrdinaryDao.findAll(specificationOrdinary, pageRequest).getContent();
if (list.isEmpty()) {
break;
}
for (FirePointOrdinaryEntity item : list) {
AddressBean addressBean = FirePointAddressUtils.analysisWithNetwork(item.getLongitude(), item.getLatitude());
if (addressBean.isSuccess()) {
//使用网络方式解析地址信息成功就对实体类对象赋值入库
item.setProCode(addressBean.getProCode());
item.setProName(addressBean.getProName());
item.setCityCode(addressBean.getCityCode());
item.setCityName(addressBean.getCityName());
item.setCountyCode(addressBean.getCountyCode());
item.setCountyName(addressBean.getCountyName());
item.setTownCode(addressBean.getTownCode());
item.setTownName(addressBean.getTownName());
item.setFirePointAddress(addressBean.getFirePointAddress());
firePointOrdinaryDao.saveAndFlush(item);
System.out.println("解析成功");
} else {
System.out.println("解析失败" + item.getId());
}
}
}
//使用天地图反查填补历史数据-end
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "OKKKK", locale);
}