山东临时火点表到全国火点表的新逻辑
This commit is contained in:
parent
9194a38a11
commit
a8e87d0422
@ -2,21 +2,17 @@ package com.xkrs.controller;
|
||||
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.common.tool.TokenUtil;
|
||||
import com.xkrs.dao.CountyCodeWeiXinDao;
|
||||
import com.xkrs.dao.FirePointDao;
|
||||
import com.xkrs.dao.ShanDongFirePointDao;
|
||||
import com.xkrs.dao.SysUserDao;
|
||||
import com.xkrs.model.entity.FirePoint;
|
||||
import com.xkrs.model.entity.FirePointEntity;
|
||||
import com.xkrs.model.entity.ShanDongFirePointEntity;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.entity.*;
|
||||
import com.xkrs.model.qo.AuditFireTypeQo;
|
||||
import com.xkrs.model.qo.FirePointQo;
|
||||
import com.xkrs.model.qo.ShanDongFirePointVerifyStateQo;
|
||||
import com.xkrs.model.vo.AppTaskBodyVo;
|
||||
import com.xkrs.service.FirePointService;
|
||||
import com.xkrs.service.StreetService;
|
||||
import com.xkrs.utils.SendSms;
|
||||
import com.xkrs.utils.WDWxSendMsgUtil;
|
||||
import com.xkrs.websocket.service.WebSocketServer;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@ -54,6 +50,9 @@ public class FirePointController {
|
||||
@Resource
|
||||
private StreetService streetService;
|
||||
|
||||
@Resource
|
||||
private CountyCodeWeiXinDao countyCodeWeiXinDao;
|
||||
|
||||
/**
|
||||
* 添加火点数据
|
||||
*
|
||||
@ -143,12 +142,17 @@ public class FirePointController {
|
||||
@GetMapping("/sem")
|
||||
public String sem() {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
try {
|
||||
WDWxSendMsgUtil.sendMsg("18447024917@chatroom", "微信发消息测试66666", 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SendSms.sendSmsToUser(new String[]{"8615764226530"}, "1425995", new String[]{"荒岛66666"});
|
||||
|
||||
CountyCodeWeiXinEntity countyCodeWeiXinEntity = new CountyCodeWeiXinEntity();
|
||||
countyCodeWeiXinEntity.setCountyCode("370000");
|
||||
countyCodeWeiXinEntity.setWeixinId("18447024917@chatroom");
|
||||
countyCodeWeiXinDao.save(countyCodeWeiXinEntity);
|
||||
// try {
|
||||
// WDWxSendMsgUtil.sendMsg("18447024917@chatroom", "微信发消息测试66666", 0);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// SendSms.sendSmsToUser(new String[]{"8615764226530"}, "1425995", new String[]{"荒岛66666"});
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "shanDongFirePointList", locale);
|
||||
}
|
||||
|
||||
|
13
src/main/java/com/xkrs/dao/CountyCodeWeiXinDao.java
Normal file
13
src/main/java/com/xkrs/dao/CountyCodeWeiXinDao.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.CountyCodeWeiXinEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@Component
|
||||
public interface CountyCodeWeiXinDao extends JpaRepository<CountyCodeWeiXinEntity, Long>, JpaSpecificationExecutor<CountyCodeWeiXinEntity> {
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "countycode_weixin")
|
||||
public class CountyCodeWeiXinEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "countycode_weixin_seq_gen")
|
||||
@SequenceGenerator(name = "countycode_weixin_seq_gen", sequenceName = "countycode_weixin_id_seq", allocationSize = 1)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 区划编码
|
||||
*/
|
||||
@Column(length = 64, columnDefinition = "varchar(64)")
|
||||
private String countyCode;
|
||||
|
||||
/**
|
||||
* 微信ID
|
||||
*/
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String weixinId;
|
||||
|
||||
public CountyCodeWeiXinEntity() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCountyCode() {
|
||||
return countyCode;
|
||||
}
|
||||
|
||||
public void setCountyCode(String countyCode) {
|
||||
this.countyCode = countyCode;
|
||||
}
|
||||
|
||||
public String getWeixinId() {
|
||||
return weixinId;
|
||||
}
|
||||
|
||||
public void setWeixinId(String weixinId) {
|
||||
this.weixinId = weixinId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CountyCodeWeiXinEntity{" + "id=" + id + ", countyCode='" + countyCode + '\'' + ", weixinId='" + weixinId + '\'' + '}';
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import com.xkrs.model.vo.AppTaskBodyVo;
|
||||
import com.xkrs.model.vo.GaoDeIgGeocodeVo;
|
||||
import com.xkrs.service.FirePointService;
|
||||
import com.xkrs.utils.*;
|
||||
import org.apache.http.util.TextUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
@ -84,6 +85,9 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
@Resource
|
||||
private NationwideDao nationwideDao;
|
||||
|
||||
@Resource
|
||||
private CountyCodeWeiXinDao countyCodeWeiXinDao;
|
||||
|
||||
/**
|
||||
* 添加火点信息
|
||||
*
|
||||
@ -125,7 +129,8 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
System.out.println("添加火点信息 逆地理编码请求街道编号失败:" + e.getMessage());
|
||||
}
|
||||
//如果开关已打开,就剔除山东的火点
|
||||
if (isSwitchStateOpen() && firePointEntity.getCountyCode().startsWith("37")) {
|
||||
boolean switchOpened = isSwitchStateOpen();
|
||||
if (switchOpened && firePointEntity.getCountyCode().startsWith("37")) {
|
||||
return null;
|
||||
}
|
||||
//如果开关已关闭,所有火点都入全国火点库
|
||||
@ -134,7 +139,12 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
return null;
|
||||
}
|
||||
log.info("-------发现新火点");
|
||||
return firePointDao.save(firePointEntity);
|
||||
FirePointEntity savedFirePointEntity = firePointDao.save(firePointEntity);
|
||||
//如果开关关闭了,山东的火点发送短信微信
|
||||
if ((!switchOpened) && firePointEntity.getCountyCode().startsWith("37")) {
|
||||
sendBroadcast(firePointEntity.getStreetCode(), firePointEntity.getFirePointAddress());
|
||||
}
|
||||
return savedFirePointEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -184,12 +194,18 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
return null;
|
||||
}
|
||||
log.info("-------发现新山东火点");
|
||||
return shanDongFirePointDao.save(firePointEntity);
|
||||
ShanDongFirePointEntity savedFirePointEntity = shanDongFirePointDao.save(firePointEntity);
|
||||
try {//微信消息通知工作组
|
||||
String content = "【星科瑞升】您注册的区域卫星监测到疑似火点," + firePointEntity.getFirePointAddress() + ",\n请登录系统查看";
|
||||
// WDWxSendMsgUtil.sendMsg(weixinId, content, 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return savedFirePointEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回开关是否为打开状态
|
||||
*
|
||||
@ -282,12 +298,94 @@ public class FirePointServiceImpl implements FirePointService {
|
||||
firePointEntity.setAuditFireType("0");//初始化火点为未审核状态
|
||||
log.info("-------转存新火点");
|
||||
firePointDao.save(firePointEntity);
|
||||
|
||||
//如果开关关闭了,山东的火点发送短信微信
|
||||
if (firePointEntity.getCountyCode().startsWith("37")) {
|
||||
sendBroadcast(firePointEntity.getStreetCode(), firePointEntity.getFirePointAddress());
|
||||
}
|
||||
}
|
||||
shanDongFirePointDao.updateVerifyStateByFireCode(fireCode, verifyState);
|
||||
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
|
||||
}
|
||||
|
||||
private void sendBroadcast(String firePointStreetCode, String firePointAddress) {
|
||||
//发送微信消息
|
||||
sendWeiXinMessage(firePointStreetCode, firePointAddress);
|
||||
//发送短信消息
|
||||
sendSMSMessage(firePointStreetCode, firePointAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送微信消息
|
||||
*
|
||||
* @param firePointStreetCode
|
||||
* @param firePointAddress
|
||||
*/
|
||||
private void sendWeiXinMessage(String firePointStreetCode, String firePointAddress) {
|
||||
List<CountyCodeWeiXinEntity> countyCodeWeiXinList = countyCodeWeiXinDao.findAll();
|
||||
if (countyCodeWeiXinList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> weixinIdList = new ArrayList<>();
|
||||
for (CountyCodeWeiXinEntity countyCodeWeiXin : countyCodeWeiXinList) {
|
||||
String countyCode = countyCodeWeiXin.getCountyCode();
|
||||
String startCountyCode = getStartCountyCode(countyCode);
|
||||
if ((!TextUtils.isEmpty(startCountyCode)) && firePointStreetCode.startsWith(startCountyCode)) {
|
||||
weixinIdList.add(countyCodeWeiXin.getWeixinId());
|
||||
}
|
||||
}
|
||||
if (weixinIdList.size() > 0) {
|
||||
String content = "【星科瑞升】您注册的区域卫星监测到疑似火点," + firePointAddress + ",\n请登录系统查看";
|
||||
for (String weixinId : weixinIdList) {
|
||||
try {
|
||||
WDWxSendMsgUtil.sendMsg(weixinId, content, 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信消息
|
||||
*
|
||||
* @param firePointStreetCode
|
||||
* @param firePointAddress
|
||||
*/
|
||||
private void sendSMSMessage(String firePointStreetCode, String firePointAddress) {
|
||||
List<SysUserEntity> sysUserList = sysUserDao.findAll();
|
||||
if (sysUserList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> telephoneList = new ArrayList<>();
|
||||
for (SysUserEntity sysUser : sysUserList) {
|
||||
String countyCode = sysUser.getCountyCode();
|
||||
String startCountyCode = getStartCountyCode(countyCode);
|
||||
if ((!TextUtils.isEmpty(startCountyCode)) && firePointStreetCode.startsWith(startCountyCode)) {
|
||||
telephoneList.add("86" + sysUser.getUserName());
|
||||
}
|
||||
}
|
||||
if (telephoneList.size() > 0) {
|
||||
String[] telephoneArray = telephoneList.toArray(new String[]{});
|
||||
// String[] telephoneArray = new String[]{"8615764226530"};
|
||||
SendSms.sendSmsToUser(telephoneArray, "1425995", new String[]{firePointAddress});
|
||||
}
|
||||
}
|
||||
|
||||
private String getStartCountyCode(String countyCode) {
|
||||
try {
|
||||
String temp = countyCode;
|
||||
while (temp.endsWith("0")) {
|
||||
temp = temp.substring(0, temp.length() - 1);
|
||||
}
|
||||
return temp;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询今天的火点信息
|
||||
*/
|
||||
|
12
src/main/java/com/xkrs/utils/BroadcastUtils.java
Normal file
12
src/main/java/com/xkrs/utils/BroadcastUtils.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
public class BroadcastUtils {
|
||||
|
||||
private BroadcastUtils() {
|
||||
}
|
||||
|
||||
// public static void send(String firePointStreetCode, String firePointAddress) {
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
@ -1,5 +1,12 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.utils.WDHttpClientUtils.sendHttpPost;
|
||||
|
||||
/**
|
||||
* @author wudong
|
||||
* @date 2022/6/2 9:25
|
||||
@ -16,8 +23,12 @@ public class WDWxSendMsgUtil {
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void sendMsg(String wxid, String text, Integer type) throws Exception {
|
||||
String url = String.format("http://118.24.27.47:10721/winxin_api/msg?wxid=%s&text=%s&type=%s", wxid, text, type);
|
||||
WDHttpClientUtils.sendHttpPost(url);
|
||||
String url = "http://118.24.27.47:10721/winxin_api/msg";
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("wxid", wxid);
|
||||
map.put("text", text);
|
||||
map.put("type", type);
|
||||
sendHttpPost(url, new ObjectMapper().writeValueAsString(map));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user