IOSchoolAction.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. package com.happy.action;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import com.happy.Model.Data2;
  5. import com.happy.Model.Data3;
  6. import com.happy.Model.OutSchool;
  7. import com.happy.Model.Visitor;
  8. import com.happy.common.http.HttpsClient;
  9. import com.happy.common.http.TimeExchange;
  10. import com.happy.service.IOSchoolService;
  11. import com.happy.unitil.CombinatorialQuery;
  12. import com.happy.unitil.CreateSign1;
  13. import com.happy.unitil.ResUtil;
  14. import com.happy.unitil.ResponseUtil;
  15. import com.opensymphony.xwork2.ActionSupport;
  16. import net.sf.json.JSONObject;
  17. import org.apache.struts2.ServletActionContext;
  18. import org.apache.struts2.interceptor.ServletRequestAware;
  19. import javax.annotation.Resource;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Calendar;
  24. import java.util.Date;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. public class IOSchoolAction extends ActionSupport implements ServletRequestAware {
  28. private HttpServletRequest request;
  29. public HttpServletResponse response;
  30. public Integer id;
  31. public String ids;
  32. private String sort;// 排序依据字段名
  33. private String order;// 排序方式
  34. private int rows;// 每页显示的行数rows
  35. private int page; // 当前页
  36. private String advanceFilter;// 组合查询条件
  37. private String filterRules;// 过滤组件条件
  38. @Resource
  39. public IOSchoolService ioSchoolService;
  40. public HttpServletRequest getRequest() {
  41. return request;
  42. }
  43. public void setRequest(HttpServletRequest request) {
  44. this.request = request;
  45. }
  46. public void setServletRequest(HttpServletRequest request) {
  47. this.request = request;
  48. }
  49. public HttpServletResponse getResponse() {
  50. return response;
  51. }
  52. public void setResponse(HttpServletResponse response) {
  53. this.response = response;
  54. }
  55. public Integer getId() {
  56. return id;
  57. }
  58. public void setId(Integer id) {
  59. this.id = id;
  60. }
  61. public String getIds() {
  62. return ids;
  63. }
  64. public void setIds(String ids) {
  65. this.ids = ids;
  66. }
  67. public String getSort() {
  68. return sort;
  69. }
  70. public void setSort(String sort) {
  71. this.sort = sort;
  72. }
  73. public String getOrder() {
  74. return order;
  75. }
  76. public void setOrder(String order) {
  77. this.order = order;
  78. }
  79. public int getRows() {
  80. return rows;
  81. }
  82. public void setRows(int rows) {
  83. this.rows = rows;
  84. }
  85. public int getPage() {
  86. return page;
  87. }
  88. public void setPage(int page) {
  89. this.page = page;
  90. }
  91. public String getAdvanceFilter() {
  92. return advanceFilter;
  93. }
  94. public void setAdvanceFilter(String advanceFilter) {
  95. this.advanceFilter = advanceFilter;
  96. }
  97. public String getFilterRules() {
  98. return filterRules;
  99. }
  100. public void setFilterRules(String filterRules) {
  101. this.filterRules = filterRules;
  102. }
  103. public String inschoolList() {
  104. // 返回前端数据
  105. JSONObject resultJson = new JSONObject();
  106. // List<User> listAll = null;
  107. List<Data2> listPage = null;
  108. int total = 0;
  109. if (sort != null || advanceFilter != null
  110. && !advanceFilter.equals("[]") || filterRules != null
  111. && !filterRules.equals("[]")) {
  112. String sql = CombinatorialQuery.queryOne(advanceFilter, sort,
  113. order, filterRules);
  114. total = ioSchoolService.findCombInschoolTotal(sql);
  115. listPage = ioSchoolService.combGetInSchoolList(sql, page, rows);
  116. } else {
  117. total = ioSchoolService.findCombInschoolTotal(" ");
  118. listPage = ioSchoolService.combGetInSchoolList(" ", page, rows);
  119. }
  120. if (total != 0) {
  121. resultJson.put("rows", listPage);
  122. resultJson.put("total", total);// 总记录数
  123. int totalPage = total % rows == 0 ? (total / rows)
  124. : (total / rows) + 1;// 总页数
  125. resultJson.put("totalPage", totalPage);
  126. resultJson.put("currentPage", page);// 当前页
  127. resultJson.put("numPerPage", rows);// 每页数
  128. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  129. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  130. resultJson.put("hasPreviousPage", true);// 有上一页
  131. resultJson.put("hasNextPage", true);// 有下一页
  132. resultJson.put("firstPage", true);// 首页
  133. resultJson.put("lastPage", true);// 尾页
  134. } else {
  135. resultJson.put("rows", "");
  136. resultJson.put("total", 0);
  137. }
  138. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  139. resultJson.toString());
  140. return null;
  141. }
  142. public String outschoolList() {
  143. // 返回前端数据
  144. JSONObject resultJson = new JSONObject();
  145. // List<User> listAll = null;
  146. List<Data3> listPage = null;
  147. int total = 0;
  148. if (sort != null || advanceFilter != null
  149. && !advanceFilter.equals("[]") || filterRules != null
  150. && !filterRules.equals("[]")) {
  151. String sql = CombinatorialQuery.queryOne(advanceFilter, sort,
  152. order, filterRules);
  153. total = ioSchoolService.findCombOutschoolTotal(sql);
  154. listPage = ioSchoolService.combGetOutSchoolList(sql, page, rows);
  155. } else {
  156. total = ioSchoolService.findCombOutschoolTotal(" ");
  157. listPage = ioSchoolService.combGetOutSchoolList(" ", page, rows);
  158. }
  159. if (total != 0) {
  160. resultJson.put("rows", listPage);
  161. resultJson.put("total", total);// 总记录数
  162. int totalPage = total % rows == 0 ? (total / rows)
  163. : (total / rows) + 1;// 总页数
  164. resultJson.put("totalPage", totalPage);
  165. resultJson.put("currentPage", page);// 当前页
  166. resultJson.put("numPerPage", rows);// 每页数
  167. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  168. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  169. resultJson.put("hasPreviousPage", true);// 有上一页
  170. resultJson.put("hasNextPage", true);// 有下一页
  171. resultJson.put("firstPage", true);// 首页
  172. resultJson.put("lastPage", true);// 尾页
  173. } else {
  174. resultJson.put("rows", "");
  175. resultJson.put("total", 0);
  176. }
  177. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  178. resultJson.toString());
  179. return null;
  180. }
  181. // 进校记录写到第三方接口
  182. public String insertIn(){
  183. Gson gson=new Gson();
  184. com.alibaba.fastjson.JSONObject js = new com.alibaba.fastjson.JSONObject();
  185. List<Data2> ins = ioSchoolService.queryInSchool();
  186. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  187. String date = sf.format(new Date());
  188. if (ins!=null){
  189. for (int i=0; i<ins.size(); i++){
  190. com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
  191. datas.put("carNumber", ins.get(i).getCar_number());
  192. datas.put("parkId", "10033845");
  193. datas.put("type", "1");
  194. if (ins.get(i).getIn_time()==null || ins.get(i).getIn_time().equals("")) {
  195. datas.put("recordTime", date);
  196. } else {
  197. datas.put("recordTime", TimeExchange.timestampToString(Integer.parseInt(ins.get(i).getIn_time())));
  198. }
  199. String msg = HttpsClient.sendJson2("https://chtech.ncjti.edu.cn/bigdata-api/api/intoAndOut/carIntoAndOutRecordUpload", datas);
  200. System.out.println(msg);
  201. HashMap<String, Object> mess = gson.fromJson(msg.toString(), new TypeToken<HashMap<String, Object>>(){}.getType());
  202. String message = mess.get("message").toString();
  203. if (message.equals("执行成功")){
  204. ioSchoolService.updateInState(ins.get(i).getId());
  205. }
  206. js.put("msg", msg);
  207. ResUtil.writeJson(ServletActionContext.getResponse(), js.toString());
  208. }
  209. }else {
  210. js.put("msg", "今日没有进入记录");
  211. ResUtil.writeJson(ServletActionContext.getResponse(), js.toString());
  212. }
  213. return null;
  214. }
  215. // 进校记录写到第三方接口
  216. public String insertOut(){
  217. Gson gson=new Gson();
  218. com.alibaba.fastjson.JSONObject js = new com.alibaba.fastjson.JSONObject();
  219. List<Data3> outs = ioSchoolService.queryOutSchool();
  220. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  221. String date = sf.format(new Date());
  222. if (outs!=null){
  223. for (int i=0; i<outs.size(); i++){
  224. com.alibaba.fastjson.JSONObject datas = new com.alibaba.fastjson.JSONObject();
  225. datas.put("carNumber", outs.get(i).getCar_number());
  226. datas.put("parkId", "10033845");
  227. datas.put("type", "2");
  228. if (outs.get(i).getOut_time() == null || outs.get(i).getOut_time().equals("")) {
  229. datas.put("recordTime", date);
  230. } else {
  231. datas.put("recordTime", TimeExchange.timestampToString(Integer.parseInt(outs.get(i).getOut_time())));
  232. }
  233. String msg = HttpsClient.sendJson2("https://chtech.ncjti.edu.cn/bigdata-api/api/intoAndOut/carIntoAndOutRecordUpload", datas);
  234. System.out.println(msg);
  235. HashMap<String, Object> mess = gson.fromJson(msg.toString(), new TypeToken<HashMap<String, Object>>(){}.getType());
  236. String message = mess.get("message").toString();
  237. if (message.equals("执行成功")){
  238. ioSchoolService.updateOutState(outs.get(i).getId());
  239. }
  240. js.put("msg", msg);
  241. ResUtil.writeJson(ServletActionContext.getResponse(), js.toString());
  242. }
  243. }else {
  244. js.put("msg", "今日没有进入记录");
  245. ResUtil.writeJson(ServletActionContext.getResponse(), js.toString());
  246. }
  247. return null;
  248. }
  249. }