| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- package com.happy.action;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.happy.Model.Visitor;
- import com.happy.common.http.HttpsClient;
- import com.happy.common.http.TimeExchange;
- import com.happy.service.VisitorService;
- import com.happy.service.userService;
- import com.happy.unitil.CombinatorialQuery;
- import com.happy.unitil.CreateSign1;
- import com.happy.unitil.ResponseUtil;
- import com.opensymphony.xwork2.ActionSupport;
- import net.sf.json.JSONObject;
- import org.apache.struts2.ServletActionContext;
- import org.apache.struts2.interceptor.ServletRequestAware;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- public class VisitorAction extends ActionSupport implements ServletRequestAware {
- private HttpServletRequest request;
- public HttpServletResponse response;
- @Resource
- public VisitorService visitorService;
- @Resource
- public userService userService;
- public Integer id;
- public String ids;
- private String sort;// 排序依据字段名
- private String order;// 排序方式
- private int rows;// 每页显示的行数rows
- private int page; // 当前页
- private String advanceFilter;// 组合查询条件
- private String filterRules;// 过滤组件条件
- public String visitor_name;
- public String visitor_phone;
- public String car_number;
- public String reason;
- public String visit_start_time;
- public String visit_end_time;
- public String member_name;
- public String member_phone;
- public String member_org;
- public String state;
- public String card_number;
- public String time;
- public HttpServletRequest getRequest() {
- return request;
- }
- public void setRequest(HttpServletRequest request) {
- this.request = request;
- }
- public void setServletRequest(HttpServletRequest request) {
- this.request = request;
- }
- public HttpServletResponse getResponse() {
- return response;
- }
- public void setResponse(HttpServletResponse response) {
- this.response = response;
- }
- public String getSort() {
- return sort;
- }
- public void setSort(String sort) {
- this.sort = sort;
- }
- public String getOrder() {
- return order;
- }
- public void setOrder(String order) {
- this.order = order;
- }
- public int getRows() {
- return rows;
- }
- public void setRows(int rows) {
- this.rows = rows;
- }
- public int getPage() {
- return page;
- }
- public void setPage(int page) {
- this.page = page;
- }
- public String getAdvanceFilter() {
- return advanceFilter;
- }
- public void setAdvanceFilter(String advanceFilter) {
- this.advanceFilter = advanceFilter;
- }
- public String getFilterRules() {
- return filterRules;
- }
- public void setFilterRules(String filterRules) {
- this.filterRules = filterRules;
- }
- public String getVisitor_name() {
- return visitor_name;
- }
- public void setVisitor_name(String visitor_name) {
- this.visitor_name = visitor_name;
- }
- public String getVisitor_phone() {
- return visitor_phone;
- }
- public void setVisitor_phone(String visitor_phone) {
- this.visitor_phone = visitor_phone;
- }
- public String getCar_number() {
- return car_number;
- }
- public void setCar_number(String car_number) {
- this.car_number = car_number;
- }
- public String getReason() {
- return reason;
- }
- public void setReason(String reason) {
- this.reason = reason;
- }
- public String getVisit_start_time() {
- return visit_start_time;
- }
- public void setVisit_start_time(String visit_start_time) {
- this.visit_start_time = visit_start_time;
- }
- public String getVisit_end_time() {
- return visit_end_time;
- }
- public void setVisit_end_time(String visit_end_time) {
- this.visit_end_time = visit_end_time;
- }
- public String getMember_name() {
- return member_name;
- }
- public void setMember_name(String member_name) {
- this.member_name = member_name;
- }
- public String getMember_phone() {
- return member_phone;
- }
- public void setMember_phone(String member_phone) {
- this.member_phone = member_phone;
- }
- public String getMember_org() {
- return member_org;
- }
- public void setMember_org(String member_org) {
- this.member_org = member_org;
- }
- public String getIds() {
- return ids;
- }
- public void setIds(String ids) {
- this.ids = ids;
- }
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getState() {
- return state;
- }
- public void setState(String state) {
- this.state = state;
- }
- public String getCard_number() {
- return card_number;
- }
- public void setCard_number(String card_number) {
- this.card_number = card_number;
- }
- public String getTime() {
- return time;
- }
- public void setTime(String time) {
- this.time = time;
- }
- public String list() {
- // 返回前端数据
- JSONObject resultJson = new JSONObject();
- // List<User> listAll = null;
- List<Visitor> listPage = null;
- int total = 0;
- if (sort != null || advanceFilter != null
- && !advanceFilter.equals("[]") || filterRules != null
- && !filterRules.equals("[]")) {
- String sql = CombinatorialQuery.queryOne(advanceFilter, sort,
- order, filterRules);
- total = visitorService.findCombPageTotal(sql);
- listPage = visitorService.combGetInfoList(sql, page, rows);
- } else {
- total = visitorService.findInfoTotal();
- listPage = visitorService.getlist(page, rows);
- }
- if (total != 0) {
- resultJson.put("rows", listPage);
- resultJson.put("total", total);// 总记录数
- int totalPage = total % rows == 0 ? (total / rows)
- : (total / rows) + 1;// 总页数
- resultJson.put("totalPage", totalPage);
- resultJson.put("currentPage", page);// 当前页
- resultJson.put("numPerPage", rows);// 每页数
- resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
- resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
- resultJson.put("hasPreviousPage", true);// 有上一页
- resultJson.put("hasNextPage", true);// 有下一页
- resultJson.put("firstPage", true);// 首页
- resultJson.put("lastPage", true);// 尾页
- } else {
- resultJson.put("rows", "");
- resultJson.put("total", 0);
- }
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- public String add(){
- JSONObject resultJson = new JSONObject();
- Visitor vs = new Visitor();
- SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String date = sf.format(new Date());
- Integer time1 = TimeExchange.StringToTimestamp(visit_start_time);
- Integer time2 = TimeExchange.StringToTimestamp(visit_end_time);
- Integer time3 = TimeExchange.StringToTimestamp(date);
- vs.setVisitor_name(visitor_name);
- vs.setVisitor_phone(visitor_phone);
- vs.setReason(reason);
- vs.setCar_number(car_number);
- vs.setCreated_time(String.valueOf(time3));
- vs.setVisit_start_time(String.valueOf(time1));
- vs.setVisit_end_time(String.valueOf(time2));
- vs.setMember_name(member_name);
- vs.setMember_phone(member_phone);
- vs.setMember_org(member_org);
- vs.setTime(date);
- int num = visitorService.insertInfo(vs);
- if (num >= 0) {
- resultJson.put("statusCode", "200");
- resultJson.put("title", "操作提示");
- resultJson.put("message", "操作成功!");
- } else {
- resultJson.put("statusCode", "500");
- resultJson.put("title", "操作提示");
- resultJson.put("message", "操作失败!");
- }
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- public String del(){
- JSONObject resultJson = new JSONObject();
- String sql = "delete from info where id in ( '" + ids.replaceAll(",", "','") + "' )";
- System.out.println(sql);
- int num = visitorService.delInfo(sql);
- if (num >= 0) {
- resultJson.put("statusCode", "200");
- resultJson.put("title", "操作提示");
- resultJson.put("message", "操作成功!");
- } else {
- resultJson.put("statusCode", "500");
- resultJson.put("title", "操作提示");
- resultJson.put("message", "操作失败!");
- }
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- public String queryById(){
- List<Visitor> list = visitorService.queryById(id);
- JSONObject info = JSONObject.fromObject(list.get(0));
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- info.toString());
- return null;
- }
- // 添加到vip白名单
- public String toWhite(){
- JSONObject resultJson = new JSONObject();
- com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
- String ukey = "6VMZEC5C6HZM7EO8";
- com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
- SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
- String date = sf.format(new Date());
- // 1新增 2编辑 3删除
- datas.put("operate_type", "1");
- // 白名单编号(收费系统唯一编号)
- datas.put("card_id", date);
- datas.put("car_number", car_number);
- datas.put("mobile", visitor_phone);
- datas.put("user_name", visitor_name);
- // 是否长期类型1是,0否,默认0
- datas.put("end_type", "0");
- datas.put("b_time", TimeExchange.StringToTimestamp(visit_start_time));
- datas.put("e_time", TimeExchange.StringToTimestamp(visit_end_time));
- // 生成带签名的字符串并使用MD5生成签名,然后转大写
- String sign = datas.toJSONString()+"key="+ukey;
- sign = CreateSign1.MD5(sign).toUpperCase();
- json.put("service_name", "white_vip");
- json.put("sign", sign);
- json.put("park_id", "10033845");
- json.put("data", datas);
- String msg = HttpsClient.sendJson2("http://istparking.sciseetech.com/public/vip/white", json);
- Gson gson=new Gson();
- HashMap<String, String> mess = gson.fromJson(msg.toString(), new TypeToken<HashMap<String, String>>(){}.getType());
- String errmsg = mess.get("errmsg");
- if (errmsg.equals("成功")){
- resultJson.put("statusCode", "200");
- resultJson.put("title", "操作提示");
- resultJson.put("message", errmsg);
- }else {
- resultJson.put("statusCode", "500");
- resultJson.put("title", "操作提示");
- resultJson.put("message", errmsg);
- }
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- // 添加到第三方访客列表
- public String toVisitor(){
- JSONObject resultJson = new JSONObject();
- com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
- if (state.equals("2")){
- resultJson.put("statusCode", "200");
- resultJson.put("title", "操作提示");
- resultJson.put("message", "此记录已推送");
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- String ukey = "6VMZEC5C6HZM7EO8";
- com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
- System.out.println("车牌号:"+car_number);
- System.out.println("时间戳:"+visit_end_time);
- datas.put("car_number", car_number);
- datas.put("begin_time", visit_start_time);
- datas.put("end_time", visit_end_time);
- datas.put("mobile", visitor_phone);
- // 生成带签名的字符串并使用MD5生成签名,然后转大写
- String sign = datas.toJSONString() + "key=" + ukey;
- sign = CreateSign1.MD5(sign).toUpperCase();
- json.put("service_name", "visitor_sync");
- json.put("sign", sign);
- json.put("park_id", "10033845");
- json.put("data", datas);
- String msg = HttpsClient.sendJson("http://istparking.sciseetech.com/public/visitor/do", json);
- userService.updateVisiStateById(id);
- Gson gson=new Gson();
- HashMap<String, String> mess = gson.fromJson(msg.toString(), new TypeToken<HashMap<String, String>>(){}.getType());
- String errmsg = mess.get("errmsg");
- System.out.println(errmsg);
- if (errmsg.equals("新增成功")){
- String msg2 = HttpsClient.sendPost(
- "https://open.wecard.qq.com/cgi-bin/oauth2/token?app_key="+
- "48103AB41FFBC5FE&app_secret=5B7FB4D3CC243695EED3693044D0FC54&grant_type=client_credentials&scope=base&ocode=1015730314", "");
- HashMap<String, String> userMap = gson.fromJson(msg2.toString(), new TypeToken<HashMap<String, String>>(){}.getType());
- String token = userMap.get("access_token");
- ArrayList<String> as = new ArrayList<>();
- as.add(card_number);
- String card = com.alibaba.fastjson.JSONObject.toJSONString(as);
- com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject();
- data.put("cards", card);
- data.put("title", "访客预约结果");
- data.put("content", "访客:"+visitor_name+"-预约成功,"+"预约时间:"+time); // 进出类别 1进、2出
- data.put("sender", "保卫处");
- String msg3 = HttpsClient.sendJson2("https://open.wecard.qq.com/cgi-bin/notice/send?access_token="+token, data);
- System.out.println(msg3);
- resultJson.put("statusCode", "200");
- resultJson.put("title", "操作提示");
- resultJson.put("message", errmsg);
- }
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- public String refuse(){
- JSONObject resultJson = new JSONObject();
- if (state.equals("2")){
- resultJson.put("statusCode", "200");
- resultJson.put("title", "操作提示");
- resultJson.put("message", "此记录已推送");
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- int m = userService.updateVisiStateNoById(id);
- if (m>0) {
- String msg3 = HttpsClient.sendPost(
- "https://open.wecard.qq.com/cgi-bin/oauth2/token?app_key="+
- "48103AB41FFBC5FE&app_secret=5B7FB4D3CC243695EED3693044D0FC54&grant_type=client_credentials&scope=base&ocode=1015730314", "");
- Gson gson = new Gson();
- HashMap<String, String> userMap = gson.fromJson(msg3.toString(), new TypeToken<HashMap<String, String>>() {
- }.getType());
- String token = userMap.get("access_token");
- ArrayList<String> as = new ArrayList<>();
- as.add(card_number);
- String json = com.alibaba.fastjson.JSONObject.toJSONString(as);
- com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject();
- data.put("cards", json);
- data.put("title", "访客预约结果");
- data.put("content", "访客:"+visitor_name+"-预约失败,"+"预约时间:"+time); // 进出类别 1进、2出
- data.put("sender", "保卫处");
- String msg2 = HttpsClient.sendJson2("https://open.wecard.qq.com/cgi-bin/notice/send?access_token=" + token, data);
- resultJson.put("statusCode", "200");
- resultJson.put("title", "操作提示");
- resultJson.put("message", "已拒绝");
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- resultJson.put("statusCode", "500");
- resultJson.put("title", "操作提示");
- resultJson.put("message", "操作失败");
- ResponseUtil.writeJson(ServletActionContext.getResponse(),
- resultJson.toString());
- return null;
- }
- }
|