package com.happy.action; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.happy.Model.Data2; import com.happy.Model.Data3; import com.happy.Model.OutSchool; import com.happy.Model.Visitor; import com.happy.common.http.HttpsClient; import com.happy.common.http.TimeExchange; import com.happy.service.IOSchoolService; import com.happy.unitil.CombinatorialQuery; import com.happy.unitil.CreateSign1; import com.happy.unitil.ResUtil; 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.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; public class IOSchoolAction extends ActionSupport implements ServletRequestAware { private HttpServletRequest request; public HttpServletResponse response; 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;// 过滤组件条件 @Resource public IOSchoolService ioSchoolService; 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 Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getIds() { return ids; } public void setIds(String ids) { this.ids = ids; } 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 inschoolList() { // 返回前端数据 JSONObject resultJson = new JSONObject(); // List listAll = null; List 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 = ioSchoolService.findCombInschoolTotal(sql); listPage = ioSchoolService.combGetInSchoolList(sql, page, rows); } else { total = ioSchoolService.findCombInschoolTotal(" "); listPage = ioSchoolService.combGetInSchoolList(" ", 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 outschoolList() { // 返回前端数据 JSONObject resultJson = new JSONObject(); // List listAll = null; List 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 = ioSchoolService.findCombOutschoolTotal(sql); listPage = ioSchoolService.combGetOutSchoolList(sql, page, rows); } else { total = ioSchoolService.findCombOutschoolTotal(" "); listPage = ioSchoolService.combGetOutSchoolList(" ", 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 insertIn(){ Gson gson=new Gson(); com.alibaba.fastjson.JSONObject js = new com.alibaba.fastjson.JSONObject(); List ins = ioSchoolService.queryInSchool(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = sf.format(new Date()); if (ins!=null){ for (int i=0; i mess = gson.fromJson(msg.toString(), new TypeToken>(){}.getType()); String message = mess.get("message").toString(); if (message.equals("执行成功")){ ioSchoolService.updateInState(ins.get(i).getId()); } js.put("msg", msg); ResUtil.writeJson(ServletActionContext.getResponse(), js.toString()); } }else { js.put("msg", "今日没有进入记录"); ResUtil.writeJson(ServletActionContext.getResponse(), js.toString()); } return null; } // 进校记录写到第三方接口 public String insertOut(){ Gson gson=new Gson(); com.alibaba.fastjson.JSONObject js = new com.alibaba.fastjson.JSONObject(); List outs = ioSchoolService.queryOutSchool(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = sf.format(new Date()); if (outs!=null){ for (int i=0; i mess = gson.fromJson(msg.toString(), new TypeToken>(){}.getType()); String message = mess.get("message").toString(); if (message.equals("执行成功")){ ioSchoolService.updateOutState(outs.get(i).getId()); } js.put("msg", msg); ResUtil.writeJson(ServletActionContext.getResponse(), js.toString()); } }else { js.put("msg", "今日没有进入记录"); ResUtil.writeJson(ServletActionContext.getResponse(), js.toString()); } return null; } }