| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- 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<User> listAll = null;
- List<Data2> 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<User> listAll = null;
- List<Data3> 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<Data2> 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<ins.size(); i++){
- com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
- datas.put("carNumber", ins.get(i).getCar_number());
- datas.put("parkId", "10033845");
- datas.put("type", "1");
- if (ins.get(i).getIn_time()==null || ins.get(i).getIn_time().equals("")) {
- datas.put("recordTime", date);
- } else {
- datas.put("recordTime", TimeExchange.timestampToString(Integer.parseInt(ins.get(i).getIn_time())));
- }
- String msg = HttpsClient.sendJson2("https://chtech.ncjti.edu.cn/bigdata-api/api/intoAndOut/carIntoAndOutRecordUpload", datas);
- System.out.println(msg);
- HashMap<String, Object> mess = gson.fromJson(msg.toString(), new TypeToken<HashMap<String, Object>>(){}.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<Data3> 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<outs.size(); i++){
- com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
- datas.put("carNumber", outs.get(i).getCar_number());
- datas.put("parkId", "10033845");
- datas.put("type", "2");
- if (outs.get(i).getOut_time() == null || outs.get(i).getOut_time().equals("")) {
- datas.put("recordTime", date);
- } else {
- datas.put("recordTime", TimeExchange.timestampToString(Integer.parseInt(outs.get(i).getOut_time())));
- }
- String msg = HttpsClient.sendJson2("https://chtech.ncjti.edu.cn/bigdata-api/api/intoAndOut/carIntoAndOutRecordUpload", datas);
- System.out.println(msg);
- HashMap<String, Object> mess = gson.fromJson(msg.toString(), new TypeToken<HashMap<String, Object>>(){}.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;
- }
- }
|