VisitorAction.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. package com.happy.action;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import com.happy.Model.Visitor;
  5. import com.happy.common.http.HttpsClient;
  6. import com.happy.common.http.TimeExchange;
  7. import com.happy.service.VisitorService;
  8. import com.happy.service.userService;
  9. import com.happy.unitil.CombinatorialQuery;
  10. import com.happy.unitil.CreateSign1;
  11. import com.happy.unitil.ResponseUtil;
  12. import com.opensymphony.xwork2.ActionSupport;
  13. import net.sf.json.JSONObject;
  14. import org.apache.struts2.ServletActionContext;
  15. import org.apache.struts2.interceptor.ServletRequestAware;
  16. import javax.annotation.Resource;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.text.SimpleDateFormat;
  20. import java.util.ArrayList;
  21. import java.util.Date;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. public class VisitorAction extends ActionSupport implements ServletRequestAware {
  25. private HttpServletRequest request;
  26. public HttpServletResponse response;
  27. @Resource
  28. public VisitorService visitorService;
  29. @Resource
  30. public userService userService;
  31. public Integer id;
  32. public String ids;
  33. private String sort;// 排序依据字段名
  34. private String order;// 排序方式
  35. private int rows;// 每页显示的行数rows
  36. private int page; // 当前页
  37. private String advanceFilter;// 组合查询条件
  38. private String filterRules;// 过滤组件条件
  39. public String visitor_name;
  40. public String visitor_phone;
  41. public String car_number;
  42. public String reason;
  43. public String visit_start_time;
  44. public String visit_end_time;
  45. public String member_name;
  46. public String member_phone;
  47. public String member_org;
  48. public String state;
  49. public String card_number;
  50. public String time;
  51. public HttpServletRequest getRequest() {
  52. return request;
  53. }
  54. public void setRequest(HttpServletRequest request) {
  55. this.request = request;
  56. }
  57. public void setServletRequest(HttpServletRequest request) {
  58. this.request = request;
  59. }
  60. public HttpServletResponse getResponse() {
  61. return response;
  62. }
  63. public void setResponse(HttpServletResponse response) {
  64. this.response = response;
  65. }
  66. public String getSort() {
  67. return sort;
  68. }
  69. public void setSort(String sort) {
  70. this.sort = sort;
  71. }
  72. public String getOrder() {
  73. return order;
  74. }
  75. public void setOrder(String order) {
  76. this.order = order;
  77. }
  78. public int getRows() {
  79. return rows;
  80. }
  81. public void setRows(int rows) {
  82. this.rows = rows;
  83. }
  84. public int getPage() {
  85. return page;
  86. }
  87. public void setPage(int page) {
  88. this.page = page;
  89. }
  90. public String getAdvanceFilter() {
  91. return advanceFilter;
  92. }
  93. public void setAdvanceFilter(String advanceFilter) {
  94. this.advanceFilter = advanceFilter;
  95. }
  96. public String getFilterRules() {
  97. return filterRules;
  98. }
  99. public void setFilterRules(String filterRules) {
  100. this.filterRules = filterRules;
  101. }
  102. public String getVisitor_name() {
  103. return visitor_name;
  104. }
  105. public void setVisitor_name(String visitor_name) {
  106. this.visitor_name = visitor_name;
  107. }
  108. public String getVisitor_phone() {
  109. return visitor_phone;
  110. }
  111. public void setVisitor_phone(String visitor_phone) {
  112. this.visitor_phone = visitor_phone;
  113. }
  114. public String getCar_number() {
  115. return car_number;
  116. }
  117. public void setCar_number(String car_number) {
  118. this.car_number = car_number;
  119. }
  120. public String getReason() {
  121. return reason;
  122. }
  123. public void setReason(String reason) {
  124. this.reason = reason;
  125. }
  126. public String getVisit_start_time() {
  127. return visit_start_time;
  128. }
  129. public void setVisit_start_time(String visit_start_time) {
  130. this.visit_start_time = visit_start_time;
  131. }
  132. public String getVisit_end_time() {
  133. return visit_end_time;
  134. }
  135. public void setVisit_end_time(String visit_end_time) {
  136. this.visit_end_time = visit_end_time;
  137. }
  138. public String getMember_name() {
  139. return member_name;
  140. }
  141. public void setMember_name(String member_name) {
  142. this.member_name = member_name;
  143. }
  144. public String getMember_phone() {
  145. return member_phone;
  146. }
  147. public void setMember_phone(String member_phone) {
  148. this.member_phone = member_phone;
  149. }
  150. public String getMember_org() {
  151. return member_org;
  152. }
  153. public void setMember_org(String member_org) {
  154. this.member_org = member_org;
  155. }
  156. public String getIds() {
  157. return ids;
  158. }
  159. public void setIds(String ids) {
  160. this.ids = ids;
  161. }
  162. public Integer getId() {
  163. return id;
  164. }
  165. public void setId(Integer id) {
  166. this.id = id;
  167. }
  168. public String getState() {
  169. return state;
  170. }
  171. public void setState(String state) {
  172. this.state = state;
  173. }
  174. public String getCard_number() {
  175. return card_number;
  176. }
  177. public void setCard_number(String card_number) {
  178. this.card_number = card_number;
  179. }
  180. public String getTime() {
  181. return time;
  182. }
  183. public void setTime(String time) {
  184. this.time = time;
  185. }
  186. public String list() {
  187. // 返回前端数据
  188. JSONObject resultJson = new JSONObject();
  189. // List<User> listAll = null;
  190. List<Visitor> listPage = null;
  191. int total = 0;
  192. if (sort != null || advanceFilter != null
  193. && !advanceFilter.equals("[]") || filterRules != null
  194. && !filterRules.equals("[]")) {
  195. String sql = CombinatorialQuery.queryOne(advanceFilter, sort,
  196. order, filterRules);
  197. total = visitorService.findCombPageTotal(sql);
  198. listPage = visitorService.combGetInfoList(sql, page, rows);
  199. } else {
  200. total = visitorService.findInfoTotal();
  201. listPage = visitorService.getlist(page, rows);
  202. }
  203. if (total != 0) {
  204. resultJson.put("rows", listPage);
  205. resultJson.put("total", total);// 总记录数
  206. int totalPage = total % rows == 0 ? (total / rows)
  207. : (total / rows) + 1;// 总页数
  208. resultJson.put("totalPage", totalPage);
  209. resultJson.put("currentPage", page);// 当前页
  210. resultJson.put("numPerPage", rows);// 每页数
  211. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  212. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  213. resultJson.put("hasPreviousPage", true);// 有上一页
  214. resultJson.put("hasNextPage", true);// 有下一页
  215. resultJson.put("firstPage", true);// 首页
  216. resultJson.put("lastPage", true);// 尾页
  217. } else {
  218. resultJson.put("rows", "");
  219. resultJson.put("total", 0);
  220. }
  221. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  222. resultJson.toString());
  223. return null;
  224. }
  225. public String add(){
  226. JSONObject resultJson = new JSONObject();
  227. Visitor vs = new Visitor();
  228. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  229. String date = sf.format(new Date());
  230. Integer time1 = TimeExchange.StringToTimestamp(visit_start_time);
  231. Integer time2 = TimeExchange.StringToTimestamp(visit_end_time);
  232. Integer time3 = TimeExchange.StringToTimestamp(date);
  233. vs.setVisitor_name(visitor_name);
  234. vs.setVisitor_phone(visitor_phone);
  235. vs.setReason(reason);
  236. vs.setCar_number(car_number);
  237. vs.setCreated_time(String.valueOf(time3));
  238. vs.setVisit_start_time(String.valueOf(time1));
  239. vs.setVisit_end_time(String.valueOf(time2));
  240. vs.setMember_name(member_name);
  241. vs.setMember_phone(member_phone);
  242. vs.setMember_org(member_org);
  243. vs.setTime(date);
  244. int num = visitorService.insertInfo(vs);
  245. if (num >= 0) {
  246. resultJson.put("statusCode", "200");
  247. resultJson.put("title", "操作提示");
  248. resultJson.put("message", "操作成功!");
  249. } else {
  250. resultJson.put("statusCode", "500");
  251. resultJson.put("title", "操作提示");
  252. resultJson.put("message", "操作失败!");
  253. }
  254. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  255. resultJson.toString());
  256. return null;
  257. }
  258. public String del(){
  259. JSONObject resultJson = new JSONObject();
  260. String sql = "delete from info where id in ( '" + ids.replaceAll(",", "','") + "' )";
  261. System.out.println(sql);
  262. int num = visitorService.delInfo(sql);
  263. if (num >= 0) {
  264. resultJson.put("statusCode", "200");
  265. resultJson.put("title", "操作提示");
  266. resultJson.put("message", "操作成功!");
  267. } else {
  268. resultJson.put("statusCode", "500");
  269. resultJson.put("title", "操作提示");
  270. resultJson.put("message", "操作失败!");
  271. }
  272. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  273. resultJson.toString());
  274. return null;
  275. }
  276. public String queryById(){
  277. List<Visitor> list = visitorService.queryById(id);
  278. JSONObject info = JSONObject.fromObject(list.get(0));
  279. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  280. info.toString());
  281. return null;
  282. }
  283. // 添加到vip白名单
  284. public String toWhite(){
  285. JSONObject resultJson = new JSONObject();
  286. com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
  287. String ukey = "6VMZEC5C6HZM7EO8";
  288. com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
  289. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  290. String date = sf.format(new Date());
  291. // 1新增 2编辑 3删除
  292. datas.put("operate_type", "1");
  293. // 白名单编号(收费系统唯一编号)
  294. datas.put("card_id", date);
  295. datas.put("car_number", car_number);
  296. datas.put("mobile", visitor_phone);
  297. datas.put("user_name", visitor_name);
  298. // 是否长期类型1是,0否,默认0
  299. datas.put("end_type", "0");
  300. datas.put("b_time", TimeExchange.StringToTimestamp(visit_start_time));
  301. datas.put("e_time", TimeExchange.StringToTimestamp(visit_end_time));
  302. // 生成带签名的字符串并使用MD5生成签名,然后转大写
  303. String sign = datas.toJSONString()+"key="+ukey;
  304. sign = CreateSign1.MD5(sign).toUpperCase();
  305. json.put("service_name", "white_vip");
  306. json.put("sign", sign);
  307. json.put("park_id", "10033845");
  308. json.put("data", datas);
  309. String msg = HttpsClient.sendJson2("http://istparking.sciseetech.com/public/vip/white", json);
  310. Gson gson=new Gson();
  311. HashMap<String, String> mess = gson.fromJson(msg.toString(), new TypeToken<HashMap<String, String>>(){}.getType());
  312. String errmsg = mess.get("errmsg");
  313. if (errmsg.equals("成功")){
  314. resultJson.put("statusCode", "200");
  315. resultJson.put("title", "操作提示");
  316. resultJson.put("message", errmsg);
  317. }else {
  318. resultJson.put("statusCode", "500");
  319. resultJson.put("title", "操作提示");
  320. resultJson.put("message", errmsg);
  321. }
  322. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  323. resultJson.toString());
  324. return null;
  325. }
  326. // 添加到第三方访客列表
  327. public String toVisitor(){
  328. JSONObject resultJson = new JSONObject();
  329. com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
  330. if (state.equals("2")){
  331. resultJson.put("statusCode", "200");
  332. resultJson.put("title", "操作提示");
  333. resultJson.put("message", "此记录已推送");
  334. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  335. resultJson.toString());
  336. return null;
  337. }
  338. String ukey = "6VMZEC5C6HZM7EO8";
  339. com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
  340. System.out.println("车牌号:"+car_number);
  341. System.out.println("时间戳:"+visit_end_time);
  342. datas.put("car_number", car_number);
  343. datas.put("begin_time", visit_start_time);
  344. datas.put("end_time", visit_end_time);
  345. datas.put("mobile", visitor_phone);
  346. // 生成带签名的字符串并使用MD5生成签名,然后转大写
  347. String sign = datas.toJSONString() + "key=" + ukey;
  348. sign = CreateSign1.MD5(sign).toUpperCase();
  349. json.put("service_name", "visitor_sync");
  350. json.put("sign", sign);
  351. json.put("park_id", "10033845");
  352. json.put("data", datas);
  353. String msg = HttpsClient.sendJson("http://istparking.sciseetech.com/public/visitor/do", json);
  354. userService.updateVisiStateById(id);
  355. Gson gson=new Gson();
  356. HashMap<String, String> mess = gson.fromJson(msg.toString(), new TypeToken<HashMap<String, String>>(){}.getType());
  357. String errmsg = mess.get("errmsg");
  358. System.out.println(errmsg);
  359. if (errmsg.equals("新增成功")){
  360. String msg2 = HttpsClient.sendPost(
  361. "https://open.wecard.qq.com/cgi-bin/oauth2/token?app_key="+
  362. "48103AB41FFBC5FE&app_secret=5B7FB4D3CC243695EED3693044D0FC54&grant_type=client_credentials&scope=base&ocode=1015730314", "");
  363. HashMap<String, String> userMap = gson.fromJson(msg2.toString(), new TypeToken<HashMap<String, String>>(){}.getType());
  364. String token = userMap.get("access_token");
  365. ArrayList<String> as = new ArrayList<>();
  366. as.add(card_number);
  367. String card = com.alibaba.fastjson.JSONObject.toJSONString(as);
  368. com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject();
  369. data.put("cards", card);
  370. data.put("title", "访客预约结果");
  371. data.put("content", "访客:"+visitor_name+"-预约成功,"+"预约时间:"+time); // 进出类别 1进、2出
  372. data.put("sender", "保卫处");
  373. String msg3 = HttpsClient.sendJson2("https://open.wecard.qq.com/cgi-bin/notice/send?access_token="+token, data);
  374. System.out.println(msg3);
  375. resultJson.put("statusCode", "200");
  376. resultJson.put("title", "操作提示");
  377. resultJson.put("message", errmsg);
  378. }
  379. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  380. resultJson.toString());
  381. return null;
  382. }
  383. public String refuse(){
  384. JSONObject resultJson = new JSONObject();
  385. if (state.equals("2")){
  386. resultJson.put("statusCode", "200");
  387. resultJson.put("title", "操作提示");
  388. resultJson.put("message", "此记录已推送");
  389. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  390. resultJson.toString());
  391. return null;
  392. }
  393. int m = userService.updateVisiStateNoById(id);
  394. if (m>0) {
  395. String msg3 = HttpsClient.sendPost(
  396. "https://open.wecard.qq.com/cgi-bin/oauth2/token?app_key="+
  397. "48103AB41FFBC5FE&app_secret=5B7FB4D3CC243695EED3693044D0FC54&grant_type=client_credentials&scope=base&ocode=1015730314", "");
  398. Gson gson = new Gson();
  399. HashMap<String, String> userMap = gson.fromJson(msg3.toString(), new TypeToken<HashMap<String, String>>() {
  400. }.getType());
  401. String token = userMap.get("access_token");
  402. ArrayList<String> as = new ArrayList<>();
  403. as.add(card_number);
  404. String json = com.alibaba.fastjson.JSONObject.toJSONString(as);
  405. com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject();
  406. data.put("cards", json);
  407. data.put("title", "访客预约结果");
  408. data.put("content", "访客:"+visitor_name+"-预约失败,"+"预约时间:"+time); // 进出类别 1进、2出
  409. data.put("sender", "保卫处");
  410. String msg2 = HttpsClient.sendJson2("https://open.wecard.qq.com/cgi-bin/notice/send?access_token=" + token, data);
  411. resultJson.put("statusCode", "200");
  412. resultJson.put("title", "操作提示");
  413. resultJson.put("message", "已拒绝");
  414. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  415. resultJson.toString());
  416. return null;
  417. }
  418. resultJson.put("statusCode", "500");
  419. resultJson.put("title", "操作提示");
  420. resultJson.put("message", "操作失败");
  421. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  422. resultJson.toString());
  423. return null;
  424. }
  425. }