hz-zhhq-app-service/greenH5modul/.svn/pristine/81/81dc0036f91e293696ebc45b26f...

227 lines
6.3 KiB
Plaintext
Raw Normal View History

2025-01-21 13:12:35 +08:00
package com.jysoft.visitor.controller;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.jysoft.visitor.service.VisitorService;
import com.jysoft.visitor.util.ArtemisPost;
import com.nationalelectirc.Constant.Constant;
import com.nationalelectirc.utils.RestResult;
import com.nationalelectric.greenH5.GreenBaseController;
import com.nationalelectric.greenH5.po.GreenUserInfo;
import com.nationalelectric.greenH5.po.GreenVisitor;
import com.nationalelectric.greenH5.po.VisitorEventNotify;
import com.sgcc.uap.persistence.IHibernateDao;
/**
* @author bonus
* @date 2023-06-13
* @描述:访客管理
*
*/
@Controller
@RequestMapping("/greenVisitor")
public class VisitorController extends GreenBaseController {
@Autowired
private VisitorService service;
final String ipHost = "192.168.8.157:8082";
/**
* 添加来访记录
*
* @param entity
* 数据
* @return 响应数据
*/
@ResponseBody
@RequestMapping(value = "/addVisitor", method = { RequestMethod.POST })
public RestResult addVisitor(GreenVisitor entity) {
try {
GreenUserInfo info = getUserInfo(entity.getUserId());
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
} catch (Exception e) {
return new RestResult(Constant.FAILED, "非法用户");
}
return service.addVisitor(entity);
}
/**
* 通过id获取邀约记录
*
* @param entity
* 数据
* @return 响应数据
*/
@ResponseBody
@RequestMapping(value = "/getVisitor", method = { RequestMethod.POST })
public RestResult getVisitor(GreenVisitor entity) {
try {
GreenUserInfo info = getUserInfo(entity.getUserId());
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
} catch (Exception e) {
return new RestResult(Constant.FAILED, "非法用户");
}
return service.getVisitor(entity);
}
/**
* 修改信息状态
*
* @param entity
* 数据
* @return 响应数据
*/
@ResponseBody
@RequestMapping(value = "/updateVisitor", method = { RequestMethod.POST })
public RestResult updateVisitor(GreenVisitor entity) {
try {
GreenUserInfo info = getUserInfo(entity.getUserId());
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
} catch (Exception e) {
return new RestResult(Constant.FAILED, "非法用户");
}
return service.updateVisitor(entity);
}
/**
* 获取个人接收的访客记录
*
* @param entity
* 数据
* @return 响应数据
*/
@ResponseBody
@RequestMapping(value = "/getReceiveVisitorByUserId", method = { RequestMethod.POST })
public RestResult getReceiveVisitorByUserId(GreenVisitor entity) {
try {
GreenUserInfo info = getUserInfo(entity.getUserId());
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
} catch (Exception e) {
return new RestResult(Constant.FAILED, "非法用户");
}
return service.getReceiveVisitorByUserId(entity);
}
/**
* 获取个人发出的访客记录
*
* @param entity
* 数据
* @return 响应数据
*/
@ResponseBody
@RequestMapping(value = "/getIssueVisitorByUserId", method = { RequestMethod.POST })
public RestResult getIssueVisitorByUserId(GreenVisitor entity) {
try {
GreenUserInfo info = getUserInfo(entity.getUserId());
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
} catch (Exception e) {
return new RestResult(Constant.FAILED, "非法用户");
}
return service.getIssueVisitorByUserId(entity);
}
/**
* 查询出行报备部门拥有审核权限人员
*
* @param map
* @return
*/
@RequestMapping(value = "/getDeptExamineAuth", method = RequestMethod.POST)
@Transactional(rollbackFor = Exception.class)
@ResponseBody
public RestResult getDeptExamineAuth(GreenVisitor entity) {
try {
GreenUserInfo info = getUserInfo(entity.getUserId());
if (info == null) {
return new RestResult(Constant.FAILED, "非法用户");
}
} catch (Exception e) {
return new RestResult(Constant.FAILED, "非法用户");
}
return service.getDeptExamineAuth(entity);
}
/**
* 访客机事件订阅
*
* @param map
* @return
*/
@RequestMapping(value = "/getVisitorEventNotify", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public RestResult getVisitorEventNotify(HttpServletRequest request, HttpServletResponse session) {
try {
JSONObject jobj = new JSONObject();
int eventTypes[] = new int[] { 1392513025,1392513026};
int eventLvl[] = new int[]{0,1,2,3};
jobj.put("eventTypes", eventTypes);
jobj.put("eventDest", "http://" + ipHost + "/greenH5/greenH5modul/rest/greenVisitor/addVisitorEventNotify");
jobj.put("eventLvl", eventLvl);
ArtemisPost.eventSubscriptionByEventTypes(jobj.toString());
System.err.println(jobj.toString());
return new RestResult(Constant.SUCCESS, "事件订阅成功");
} catch (Exception e) {
e.printStackTrace();
return new RestResult(Constant.FAILED, "事件订阅失败");
}
}
/**
* 访客机事件订阅
*
* @param map
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "/addVisitorEventNotify", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public void addVisitorEventNotify(HttpServletRequest request, HttpSession session) {
try {
BufferedReader bufferReader;
bufferReader = new BufferedReader(request.getReader());
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = bufferReader.readLine()) != null) {
sb.append(line);
}
final String result = sb.toString();
service.addVisitorEventNotify(result);
} catch (IOException e) {
e.printStackTrace();
}
}
}