Commit 62c1d365 by cc150520900118

资源文件配置

parent 92943058
package com.founder.commonutils.publicEntity;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
//统一返回结果的类
@Data
public class MapRestResult <T>{
@ApiModelProperty(value = "是否成功")
private Boolean success;
import java.util.List;
@ApiModelProperty(value = "返回码")
private Integer code;
/**
* Xzxt-Rest自定义响应结构
*/
public class MapRestResult<T> {
@ApiModelProperty(value = "返回消息")
private String message;
// 定义jackson对象
private static final ObjectMapper MAPPER = new ObjectMapper();
@ApiModelProperty(value = "数据总数(分页总数时使用)")
private Object count;
// 响应业务状态
@ApiModelProperty(value="响应业务状态")
private Integer status;
@ApiModelProperty(value = "返回数据")
private T data ;
// 响应消息
@ApiModelProperty(value="响应消息")
private String msg;
//把构造方法私有
private MapRestResult() {}
// 响应中的数据
@ApiModelProperty(value="响应的数据")
private T data;
//成功静态方法
public static MapRestResult ok() {
//redis key
@ApiModelProperty(value="数据总数")
private Object count;
//--------1---------------
public static <T> MapRestResult build(Integer status, String msg, T data) {
return new MapRestResult(status, msg, data);
}
//--------2---------------
public static <T> MapRestResult build(Integer status, String msg, Object count, T data) {
return new MapRestResult(status, msg, count,data);
}
//--------3---------------
public static <T> MapRestResult ok(T data) {
return new MapRestResult(data);
}
//--------4---------------
public static <T> MapRestResult ok() {
return new MapRestResult();
}
//--------5---------------
public static <T> MapRestResult error() {
MapRestResult r = new MapRestResult();
r.setSuccess(true);
r.setCode(ResultCode.SUCCESS);
r.setMessage("成功");
r.setStatus(ResultCode.ERROR);
r.setMsg("error");
r.setMsg("失败");
return r;
}
//失败静态方法
public static MapRestResult error() {
MapRestResult r = new MapRestResult();
r.setSuccess(false);
r.setCode(ResultCode.ERROR);
r.setMessage("失败");
return r;
public MapRestResult() {
this.status = 200;
this.msg = "OK";
this.data = data;
}
public MapRestResult(Integer status, String msg, T data) {
this.status = status;
this.msg = msg;
this.data = data;
}
public MapRestResult(Integer status, String msg, Object count, T data) {
this.status = status;
this.msg = msg;
this.count=count;
this.data = data;
}
public MapRestResult(T data) {
this.status = 200;
this.msg = "OK";
this.data = data;
}
public MapRestResult success(Boolean success){
this.setSuccess(success);
return this;
public Integer getStatus() {
return status;
}
public MapRestResult message(String message){
this.setMessage(message);
return this;
public void setStatus(Integer status) {
this.status = status;
}
public MapRestResult code(Integer code){
this.setCode(code);
return this;
public String getMsg() {
return msg;
}
public MapRestResult count(Object count){
this.setCount(count);
return this;
public void setMsg(String msg) {
this.msg = msg;
}
public MapRestResult data(T data){
this.data=data;
return this;
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public Object getCount() {
return count;
}
public void setCount(Object count) {
this.count = count;
}
/**
* 将json结果集转化为Xzxt-Rest对象
*
* @param jsonData json数据
* @param clazz Xzxt-Rest中的object类型
* @return
*/
public static MapRestResult formatToPojo(String jsonData, Class<?> clazz) {
try {
if (clazz == null) {
return MAPPER.readValue(jsonData, MapRestResult.class);
}
JsonNode jsonNode = MAPPER.readTree(jsonData);
JsonNode data = jsonNode.get("data");
Object obj = null;
if (clazz != null) {
if (data.isObject()) {
obj = MAPPER.readValue(data.traverse(), clazz);
} else if (data.isTextual()) {
obj = MAPPER.readValue(data.asText(), clazz);
}
}
return build(jsonNode.get("status").intValue(), jsonNode.get("msg").asText(), obj);
} catch (Exception e) {
System.out.println(e.getStackTrace());
return new MapRestResult();
}
}
/**
* object对象的转化
*
* @param json
* @return
*/
public static MapRestResult format(String json) {
try {
return MAPPER.readValue(json, MapRestResult.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* Object是集合转化
*
* @param jsonData json数据
* @param clazz 集合中的类型
* @return
*/
public static MapRestResult formatToList(String jsonData, Class<?> clazz) {
try {
JsonNode jsonNode = MAPPER.readTree(jsonData);
JsonNode data = jsonNode.get("data");
Object obj = null;
if (data.isArray() && data.size() > 0) {
obj = MAPPER.readValue(data.traverse(),
MAPPER.getTypeFactory().constructCollectionType(List.class, clazz));
}
return build(jsonNode.get("status").intValue(), jsonNode.get("msg").asText(), obj);
} catch (Exception e) {
return null;
}
}
}
package com.founder.commonutils.publicEntity;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
/**
* Xzxt-Rest自定义响应结构
*/
public class XzxtRestResult<T> {
// 定义jackson对象
private static final ObjectMapper MAPPER = new ObjectMapper();
// 响应业务状态
@ApiModelProperty(value="响应业务状态")
private Integer status;
// 响应消息
@ApiModelProperty(value="响应消息")
private String msg;
// 响应中的数据
@ApiModelProperty(value="响应的数据")
private T data;
//redis key
@ApiModelProperty(value="redis的key值")
private String rediskey;
public static <T> XzxtRestResult build(Integer status, String msg, T data) {
return new XzxtRestResult(status, msg, data);
}
public static <T> XzxtRestResult ok(T data) {
return new XzxtRestResult(data);
}
public static <T> XzxtRestResult ok(int i, String count, List<T> list) {
return new XzxtRestResult(null);
}
public XzxtRestResult() {
}
public static <T> XzxtRestResult build(Integer status, String msg, String reidskey, T data) {
return new XzxtRestResult(status, msg, reidskey,data);
}
public XzxtRestResult(Integer status, String msg, T data) {
this.status = status;
this.msg = msg;
this.data = data;
}
public XzxtRestResult(Integer status, String msg, String reidskey, T data) {
this.status = status;
this.msg = msg;
this.rediskey=reidskey;
this.data = data;
}
public XzxtRestResult(T data) {
this.status = 200;
this.msg = "OK";
this.data = data;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getRediskey() {
return rediskey;
}
public void setRediskey(String rediskey) {
this.rediskey = rediskey;
}
/**
* 将json结果集转化为Xzxt-Rest对象
*
* @param jsonData json数据
* @param clazz Xzxt-Rest中的object类型
* @return
*/
public static XzxtRestResult formatToPojo(String jsonData, Class<?> clazz) {
try {
if (clazz == null) {
return MAPPER.readValue(jsonData, XzxtRestResult.class);
}
JsonNode jsonNode = MAPPER.readTree(jsonData);
JsonNode data = jsonNode.get("data");
Object obj = null;
if (clazz != null) {
if (data.isObject()) {
obj = MAPPER.readValue(data.traverse(), clazz);
} else if (data.isTextual()) {
obj = MAPPER.readValue(data.asText(), clazz);
}
}
return build(jsonNode.get("status").intValue(), jsonNode.get("msg").asText(), obj);
} catch (Exception e) {
System.out.println(e.getStackTrace());
return new XzxtRestResult();
}
}
/**
* object对象的转化
*
* @param json
* @return
*/
public static XzxtRestResult format(String json) {
try {
return MAPPER.readValue(json, XzxtRestResult.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* Object是集合转化
*
* @param jsonData json数据
* @param clazz 集合中的类型
* @return
*/
public static XzxtRestResult formatToList(String jsonData, Class<?> clazz) {
try {
JsonNode jsonNode = MAPPER.readTree(jsonData);
JsonNode data = jsonNode.get("data");
Object obj = null;
if (data.isArray() && data.size() > 0) {
obj = MAPPER.readValue(data.traverse(),
MAPPER.getTypeFactory().constructCollectionType(List.class, clazz));
}
return build(jsonNode.get("status").intValue(), jsonNode.get("msg").asText(), obj);
} catch (Exception e) {
return null;
}
}
}
......@@ -21,7 +21,10 @@
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided </scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!--spring切面aop依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
......
package com.founder.servicebase.logs;
import com.founder.servicebase.meassage.WebSocketServer;
import lombok.SneakyThrows;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
......@@ -104,6 +105,14 @@ public class SysLogAspect {
System.out.print("保存数据库=="+sysLog.toString());
//调用service保存SysLog实体类到数据库
//sysLogService.save(sysLog);
WebSocketServer.BroadCastInfo(
"---时间:"+sysLog.getCreateDate()+
"\n---用户:"+sysLog.getUserId()+
"\n---请求ip:"+sysLog.getIp()+
"\n---是否成功:"+sysLog.getMessage()+
"\n---调用的方法:"+sysLog.getMethod()+
"\n---传入参数:"+sysLog.getParams()+
"\n---返回结果:"+sysLog.getContent());
return null;
}
/**
......
package com.founder.servicebase.meassage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* @Author:changchao
* @Description:
* @Date: Created in 上午11:15 2021/3/10
*/
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter(){
return new ServerEndpointExporter();
}
}
\ No newline at end of file
package com.founder.servicebase.meassage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
@ServerEndpoint(value = "/ws/asset")
@Component
public class WebSocketServer {
@PostConstruct
public void init() {
System.out.println("websocket 加载");
}
private static Logger log = LoggerFactory.getLogger(WebSocketServer.class);
private static final AtomicInteger OnlineCount = new AtomicInteger(0);
// concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。
private static CopyOnWriteArraySet<Session> SessionSet = new CopyOnWriteArraySet<Session>();
/**
* 连接建立成功调用的方法
*/
@OnOpen
public void onOpen(Session session) {
SessionSet.add(session);
int cnt = OnlineCount.incrementAndGet(); // 在线数加1
log.info("有连接加入,当前连接数为:{}", cnt);
SendMessage(session, "连接成功");
}
/**
* 连接关闭调用的方法
*/
@OnClose
public void onClose(Session session) {
SessionSet.remove(session);
int cnt = OnlineCount.decrementAndGet();
log.info("有连接关闭,当前连接数为:{}", cnt);
}
/**
* 收到客户端消息后调用的方法
*
* @param message
* 客户端发送过来的消息
*/
@OnMessage
public void onMessage(String message, Session session) {
log.info("来自客户端的消息:{}",message);
SendMessage(session, "收到消息,消息内容:"+message);
}
/**
* 出现错误
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.error("发生错误:{},Session ID: {}",error.getMessage(),session.getId());
error.printStackTrace();
}
/**
* 发送消息,实践表明,每次浏览器刷新,session会发生变化。
* @param session
* @param message
*/
public static void SendMessage(Session session, String message) {
try {
// session.getBasicRemote().sendText(String.format("%s (From Server,Session ID=%s)",message,session.getId()));
session.getBasicRemote().sendText(message);
} catch (IOException e) {
log.error("发送消息出错:{}", e.getMessage());
e.printStackTrace();
}
}
/**
* 群发消息
* @param message
* @throws IOException
*/
public static void BroadCastInfo(String message) throws IOException {
for (Session session : SessionSet) {
if(session.isOpen()){
SendMessage(session, message);
}
}
}
/**
* 指定Session发送消息
* @param sessionId
* @param message
* @throws IOException
*/
public static void SendMessage(String message,String sessionId) throws IOException {
Session session = null;
for (Session s : SessionSet) {
if(s.getId().equals(sessionId)){
session = s;
break;
}
}
if(session!=null){
SendMessage(session, message);
}
else{
log.warn("没有找到你指定ID的会话:{}",sessionId);
}
}
}
\ No newline at end of file
......@@ -52,7 +52,7 @@ public class TbStAsjController {
receiving.setSsdw(ssdw);//设置所属单位,用于案件类别代码转译
//return tbStAsjService.selectAsjxxList(receiving);
List<TbStAsj> asjList = tbStAsjService.selectAsjxxList(receiving);
return MapRestResult.ok().data(asjList);
return MapRestResult.ok(asjList);
}
@OperLog(message = "按条件查询案件",operation = OperationType.QUERY)
......@@ -82,7 +82,7 @@ public class TbStAsjController {
wrapper.le("ASJFSSJ_ASJFSJSSJ", end);
}
List<TbStAsj> list = tbStAsjService.list(wrapper);
return MapRestResult.ok().data(list);
return MapRestResult.ok(list);
}
@OperLog(message = "获取所有案件(带分页)",operation = OperationType.QUERY)
......@@ -95,7 +95,7 @@ public class TbStAsjController {
tbStAsjService.page(pageAsj, null);
long total = pageAsj.getTotal();//总记录数
List<TbStAsj> records = pageAsj.getRecords(); //数据list集合
return MapRestResult.ok().count(total).data(records);
return MapRestResult.build(202,"成功获取案件信息",total,records);
}
@OperLog(message = "带条件查询所有案件(带分页)",operation = OperationType.QUERY)
......@@ -132,7 +132,7 @@ public class TbStAsjController {
tbStAsjService.page(pageAsj,wrapper);
long total = pageAsj.getTotal();//总记录数
List<TbStAsj> records = pageAsj.getRecords(); //数据list集合
return MapRestResult.ok().count(total).data(records);
return MapRestResult.build(202,"成功获取案件信息",total,records);
}
@OperLog(message = "修改案件",operation = OperationType.QUERY)
......@@ -432,7 +432,7 @@ public class TbStAsjController {
}
System.out.println("线索组和串并组返回的Alllist="+acb.toString());
return MapRestResult.ok().data(acb);
return MapRestResult.ok(acb);
}
}
......@@ -31,6 +31,6 @@ public class EsExtractController {
e.printStackTrace();
}
int count = (int) esSearch.EScount(jz_index);
return MapRestResult.ok().message("基站数据抽取完成" + count);
return MapRestResult.build(200,"基站数据抽取完成", count);
}
}
package com.founder.eszy.controller;
import com.founder.commonutils.publicEntity.*;
import com.founder.commonutils.publicEntity.GeographicInfo;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.commonutils.publicEntity.RequestBean;
import com.founder.eszy.esSearch.EsTbZyJzxxTranslationQuery;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.common.geo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -40,20 +41,20 @@ public class EsQueryController {
}catch (Exception e){
e.printStackTrace();
}
return MapRestResult.ok().count(result.size()).data(result);
return MapRestResult.build(200,"成功查询基站数据",result.size()+"",result);
}else{
try {
result = esTbZyJzxxTranslationQuery.searchGeoPolygon(bean.getIndex(),bean.getType(),geographicInfo.getField(),geographicInfo.getPoints());
}catch (Exception e){
e.printStackTrace();
}
return MapRestResult.ok().count(result.size()).data(result);
return MapRestResult.build(200,"成功查询基站数据",result.size()+"",result);
}
}
//不带区域信息查询es数据
else{
result = esTbZyJzxxTranslationQuery.searchQuery(bean.getIndex(),bean.getType(),null,null);
return MapRestResult.ok().count(result.size()).data(result);
return MapRestResult.build(200,"成功查询基站数据",result.size()+"",result);
}
}
}
......@@ -51,7 +51,8 @@ public class RyController {
// TODO: handle exception
}
ryxx=getryJbxxxmls(esbServiceReturn);
return MapRestResult.ok().code(200).message("成功获取全国常口人员信息").data(ryxx);
return MapRestResult.build(200,"成功获取全国常口人员信息",ryxx);
}
public TbStRy getryJbxxxmls(String esb_result){
......@@ -242,9 +243,9 @@ public class RyController {
carRy.setCarType(qgjdc.getClpp1());// 车辆_品牌型号
carRy.setHjdqhdz(ry.getHjdqhdz());// 户籍地地址
carRy.setCsrq(ry.getCsrq());// 出生日期
return MapRestResult.ok().code(200).message("成功获取全国车辆人员信息").data(carRy);
return MapRestResult.build(200,"成功获取全国车辆人员信息",carRy);
}catch (Exception e){
return MapRestResult.error().code(500).message("请求失败").data(null);
return MapRestResult.error();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment