Water.java 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  1. package com.happy.action;
  2. import com.happy.Model.*;
  3. import com.happy.Until.DBtoExcel;
  4. import com.happy.Until.ResponseUtil;
  5. import com.happy.service.WaterService;
  6. import com.opensymphony.xwork2.ActionSupport;
  7. import net.sf.json.JSONObject;
  8. import org.apache.struts2.ServletActionContext;
  9. import org.apache.struts2.interceptor.ServletRequestAware;
  10. import org.springframework.context.ApplicationContext;
  11. import org.springframework.context.support.ClassPathXmlApplicationContext;
  12. import javax.annotation.Resource;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import javax.sql.DataSource;
  16. import java.sql.*;
  17. import java.text.DateFormat;
  18. import java.text.SimpleDateFormat;
  19. import java.util.*;
  20. import java.util.Date;
  21. public class Water extends ActionSupport implements ServletRequestAware {
  22. private HttpServletRequest request;
  23. public HttpServletResponse response;
  24. public int page; // 当前页
  25. public int rows;// 每页显示的行数rows
  26. public String build;
  27. public String user_id;
  28. public int id;
  29. public String dom;
  30. public String username;
  31. public String stu_number;
  32. public String time;
  33. public String begin_time;
  34. public String end_time;
  35. public double rate;
  36. public String number;
  37. public String name;
  38. public String password;
  39. public String day;
  40. public String month;
  41. public String year;
  42. public String user_name;
  43. public String use_amount;
  44. public String re_time;
  45. @Resource
  46. public WaterService waterService;
  47. public HttpServletRequest getRequest() {
  48. return request;
  49. }
  50. public void setRequest(HttpServletRequest request) {
  51. this.request = request;
  52. }
  53. public void setServletRequest(HttpServletRequest request) {
  54. this.request = request;
  55. }
  56. public HttpServletResponse getResponse() {
  57. return response;
  58. }
  59. public void setResponse(HttpServletResponse response) {
  60. this.response = response;
  61. }
  62. public int getPage() {
  63. return page;
  64. }
  65. public void setPage(int page) {
  66. this.page = page;
  67. }
  68. public int getRows() {
  69. return rows;
  70. }
  71. public void setRows(int rows) {
  72. this.rows = rows;
  73. }
  74. public String getBuild() {
  75. return build;
  76. }
  77. public void setBuild(String build) {
  78. this.build = build;
  79. }
  80. public String getUser_id() {
  81. return user_id;
  82. }
  83. public void setUser_id(String user_id) {
  84. this.user_id = user_id;
  85. }
  86. public int getId() {
  87. return id;
  88. }
  89. public void setId(int id) {
  90. this.id = id;
  91. }
  92. public String getDom() {
  93. return dom;
  94. }
  95. public void setDom(String dom) {
  96. this.dom = dom;
  97. }
  98. public String getUsername() {
  99. return username;
  100. }
  101. public void setUsername(String username) {
  102. this.username = username;
  103. }
  104. public String getStu_number() {
  105. return stu_number;
  106. }
  107. public void setStu_number(String stu_number) {
  108. this.stu_number = stu_number;
  109. }
  110. public String getTime() {
  111. return time;
  112. }
  113. public void setTime(String time) {
  114. this.time = time;
  115. }
  116. public String info(){
  117. return "info";
  118. }
  119. public String getBegin_time() {
  120. return begin_time;
  121. }
  122. public void setBegin_time(String begin_time) {
  123. this.begin_time = begin_time;
  124. }
  125. public String getEnd_time() {
  126. return end_time;
  127. }
  128. public void setEnd_time(String end_time) {
  129. this.end_time = end_time;
  130. }
  131. public double getRate() {
  132. return rate;
  133. }
  134. public void setRate(double rate) {
  135. this.rate = rate;
  136. }
  137. public String getNumber() {
  138. return number;
  139. }
  140. public void setNumber(String number) {
  141. this.number = number;
  142. }
  143. public String getName() {
  144. return name;
  145. }
  146. public void setName(String name) {
  147. this.name = name;
  148. }
  149. public String getPassword() {
  150. return password;
  151. }
  152. public void setPassword(String password) {
  153. this.password = password;
  154. }
  155. public String getDay() {
  156. return day;
  157. }
  158. public void setDay(String day) {
  159. this.day = day;
  160. }
  161. public String getMonth() {
  162. return month;
  163. }
  164. public void setMonth(String month) {
  165. this.month = month;
  166. }
  167. public String getYear() {
  168. return year;
  169. }
  170. public void setYear(String year) {
  171. this.year = year;
  172. }
  173. public String getUser_name() {
  174. return user_name;
  175. }
  176. public void setUser_name(String user_name) {
  177. this.user_name = user_name;
  178. }
  179. public String getUse_amount() {
  180. return use_amount;
  181. }
  182. public void setUse_amount(String use_amount) {
  183. this.use_amount = use_amount;
  184. }
  185. public String getRe_time() {
  186. return re_time;
  187. }
  188. public void setRe_time(String re_time) {
  189. this.re_time = re_time;
  190. }
  191. // 设备管理
  192. public String list() {
  193. JSONObject resultJson = new JSONObject();
  194. int total = waterService.findPageTotal();// 查询表中的总记录数
  195. List<Build_water> listPage = waterService.getbuild(page, rows);// 查询分页
  196. if (listPage == null) {
  197. resultJson.put("rows", "");
  198. resultJson.put("total", 0);
  199. } else {
  200. resultJson.put("rows", listPage);
  201. // int total = listAll.size();
  202. resultJson.put("total", total);// 总记录数
  203. int totalPage = total % rows == 0 ? (total / rows)
  204. : (total / rows) + 1;// 总页数
  205. resultJson.put("totalPage", totalPage);
  206. resultJson.put("currentPage", page);// 当前页
  207. resultJson.put("numPerPage", rows);// 每页数
  208. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  209. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  210. resultJson.put("hasPreviousPage", true);// 有上一页
  211. resultJson.put("hasNextPage", true);// 有下一页
  212. resultJson.put("firstPage", true);// 首页
  213. resultJson.put("lastPage", true);// 尾页
  214. }
  215. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  216. resultJson.toString());
  217. return null;
  218. }
  219. public String querylist() {
  220. JSONObject resultJson = new JSONObject();
  221. StringBuilder sb = new StringBuilder();
  222. StringBuilder sb2 = new StringBuilder();
  223. if (this.build != null) {
  224. sb.append(" and build='" + this.build + "'");
  225. sb2.append(" and build='" + this.build + "'");
  226. }
  227. if (this.user_id != null) {
  228. sb.append(" and user_id like '%" + this.user_id + "%'");
  229. sb2.append(" and user_id like '%" + this.user_id + "%'");
  230. }
  231. int start = (page - 1) * rows;// 每页的起始下标
  232. sb.append(" order by id asc limit "+start+", "+rows);
  233. int total = this.waterService.total(sb2.toString());
  234. List<Build_water> pp = this.waterService.findAllN(sb.toString());
  235. System.out.println(pp);
  236. if (pp == null) {
  237. resultJson.put("rows", "");
  238. resultJson.put("total", 0);
  239. } else {
  240. resultJson.put("rows", pp);
  241. // int total = listAll.size();
  242. resultJson.put("total", total);// 总记录数
  243. int totalPage = total % rows == 0 ? (total / rows)
  244. : (total / rows) + 1;// 总页数
  245. resultJson.put("totalPage", totalPage);
  246. resultJson.put("currentPage", page);// 当前页
  247. resultJson.put("numPerPage", rows);// 每页数
  248. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  249. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  250. resultJson.put("hasPreviousPage", true);// 有上一页
  251. resultJson.put("hasNextPage", true);// 有下一页
  252. resultJson.put("firstPage", true);// 首页
  253. resultJson.put("lastPage", true);// 尾页
  254. }
  255. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  256. return null;
  257. }
  258. public String updateBuild(){
  259. JSONObject resultJson = new JSONObject();
  260. Build_water bw = new Build_water();
  261. bw.setId(id);
  262. bw.setBuild(build);
  263. bw.setDom(dom);
  264. bw.setUser_id(user_id);
  265. System.out.println(222);
  266. int m = waterService.updateBuild(bw);
  267. System.out.println(m);
  268. if (m>0){
  269. resultJson.put("msg", "修改成功");
  270. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  271. return null;
  272. }
  273. resultJson.put("msg", "修改失败");
  274. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  275. return null;
  276. }
  277. public String delBuild(){
  278. JSONObject resultJson = new JSONObject();
  279. int m = waterService.delBuild(id);
  280. if (m>0){
  281. resultJson.put("msg", "删除成功");
  282. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  283. return null;
  284. }
  285. resultJson.put("msg", "删除失败");
  286. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  287. return null;
  288. }
  289. // 增加设备
  290. public String addBuild(){
  291. JSONObject resultJson = new JSONObject();
  292. Build_water bw = new Build_water();
  293. bw.setSchool("墨轩湖校区");
  294. bw.setBuild(build);
  295. bw.setDom(dom);
  296. bw.setUser_id(user_id);
  297. String floors = dom.charAt(0)+"层";
  298. bw.setFloors(floors);
  299. int m = waterService.addBuild(bw);
  300. if (m>0){
  301. resultJson.put("msg", "添加成功");
  302. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  303. return null;
  304. }
  305. resultJson.put("msg", "添加失败");
  306. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  307. return null;
  308. }
  309. // 导出表格
  310. public String toExcel(){
  311. JSONObject resultJson = new JSONObject();
  312. // 项目路径地址
  313. String path = request.getSession().getServletContext()
  314. .getRealPath("/download/");// File.separator
  315. ApplicationContext ac = new ClassPathXmlApplicationContext(
  316. "applicationContext.xml");
  317. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  318. Connection conn = null;
  319. ResultSet rs = null;
  320. try {
  321. conn = dataSource.getConnection();
  322. PreparedStatement ps = conn.prepareStatement("select * from build_water order by id asc");
  323. rs = ps.executeQuery();
  324. System.out.println("成功获取数据");
  325. Vector columnName = new Vector();
  326. columnName.add("id");
  327. columnName.add("school");
  328. columnName.add("build");
  329. columnName.add("floors");
  330. columnName.add("dom");
  331. columnName.add("user_id");
  332. // 导出文件
  333. new DBtoExcel().WriteExcel(rs, path + "设备信息" + "Report.xls",
  334. "sheet1", columnName);
  335. ps.close();
  336. String url = request.getSession().getServletContext().getContextPath();
  337. System.out.println();
  338. resultJson.put("downurl", url+"/download/设备信息" + "Report.xls");
  339. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  340. resultJson.toString());
  341. } catch (SQLException e) {
  342. // TODO Auto-generated catch block
  343. e.printStackTrace();
  344. } finally {
  345. try {
  346. if (conn != null) {
  347. conn.close();
  348. }
  349. } catch (SQLException e) {
  350. // TODO: handle exception
  351. }
  352. }
  353. return null;
  354. }
  355. // 用户余额列表
  356. public String Money(){
  357. JSONObject resultJson = new JSONObject();
  358. StringBuilder s1 = new StringBuilder();
  359. StringBuilder s2 = new StringBuilder();
  360. if (user_name!=null){
  361. s1.append(" and user_name like '%"+ user_name +"%'");
  362. s2.append(" and user_name like '%"+ user_name +"%'");
  363. }
  364. int total = waterService.findUsersTotal(s2.toString());// 查询表中的总记录数
  365. List<Users> listPage = waterService.queryMoney(page, rows, s1.toString());// 查询分页
  366. if (listPage == null) {
  367. resultJson.put("rows", "");
  368. resultJson.put("total", 0);
  369. } else {
  370. resultJson.put("rows", listPage);
  371. // int total = listAll.size();
  372. resultJson.put("total", total);// 总记录数
  373. int totalPage = total % rows == 0 ? (total / rows)
  374. : (total / rows) + 1;// 总页数
  375. resultJson.put("totalPage", totalPage);
  376. resultJson.put("currentPage", page);// 当前页
  377. resultJson.put("numPerPage", rows);// 每页数
  378. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  379. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  380. resultJson.put("hasPreviousPage", true);// 有上一页
  381. resultJson.put("hasNextPage", true);// 有下一页
  382. resultJson.put("firstPage", true);// 首页
  383. resultJson.put("lastPage", true);// 尾页
  384. }
  385. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  386. resultJson.toString());
  387. return null;
  388. }
  389. // 总余额
  390. public String findMoneyTotal(){
  391. JSONObject resultJson = new JSONObject();
  392. ApplicationContext ac = new ClassPathXmlApplicationContext(
  393. "applicationContext.xml");
  394. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  395. Connection conn = null;
  396. ResultSet rs = null;
  397. try {
  398. conn = dataSource.getConnection();
  399. PreparedStatement ps = conn.prepareStatement("select sum(balance) as total from users ");
  400. rs = ps.executeQuery();
  401. System.out.println("成功获取数据");
  402. String money = "";
  403. while (rs.next()){
  404. money = rs.getString("total");
  405. }
  406. resultJson.put("money", money);
  407. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  408. resultJson.toString());
  409. } catch (SQLException e) {
  410. // TODO Auto-generated catch block
  411. e.printStackTrace();
  412. } finally {
  413. try {
  414. if (conn != null) {
  415. conn.close();
  416. }
  417. } catch (SQLException e) {
  418. // TODO: handle exception
  419. }
  420. }
  421. return null;
  422. }
  423. // 个人充值明细
  424. public String findRecharge(){
  425. JSONObject resultJson = new JSONObject();
  426. StringBuilder sb = new StringBuilder();
  427. StringBuilder sb2 = new StringBuilder();
  428. if (this.stu_number != null) {
  429. sb.append(" and stu_number = '" + this.stu_number + "' ");
  430. sb2.append(" and stu_number = '" + this.stu_number + "' ");
  431. }
  432. if (this.time != null) {
  433. sb.append(" and re_time like '" + this.time + "%' ");
  434. sb2.append(" and re_time like '" + this.time + "%' ");
  435. }
  436. int total = this.waterService.chargeTotal(sb2.toString());
  437. System.out.println(total);
  438. int start = (page - 1) * rows;// 每页的起始下标
  439. sb.append(" order by id asc limit "+start+", "+rows+";");
  440. List<Recharge> pp = this.waterService.chargeRecord(sb.toString());
  441. System.out.println(pp);
  442. if (pp == null) {
  443. resultJson.put("rows", "");
  444. resultJson.put("total", 0);
  445. } else {
  446. resultJson.put("rows", pp);
  447. // int total = listAll.size();
  448. resultJson.put("total", total);// 总记录数
  449. int totalPage = total % rows == 0 ? (total / rows)
  450. : (total / rows) + 1;// 总页数
  451. resultJson.put("totalPage", totalPage);
  452. resultJson.put("currentPage", page);// 当前页
  453. resultJson.put("numPerPage", rows);// 每页数
  454. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  455. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  456. resultJson.put("hasPreviousPage", true);// 有上一页
  457. resultJson.put("hasNextPage", true);// 有下一页
  458. resultJson.put("firstPage", true);// 首页
  459. resultJson.put("lastPage", true);// 尾页
  460. }
  461. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  462. return null;
  463. }
  464. // 个人充值总额
  465. public String rechargeTotal(){
  466. JSONObject resultJson = new JSONObject();
  467. ApplicationContext ac = new ClassPathXmlApplicationContext(
  468. "applicationContext.xml");
  469. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  470. StringBuffer sb = new StringBuffer("select sum(account) as total from recharge where pay_state=2 ");
  471. if (this.stu_number != null) {
  472. sb.append(" and stu_number = '" + this.stu_number + "' ");
  473. }
  474. if (this.time != null) {
  475. sb.append(" and re_time like '" + this.time + "%' ");
  476. }
  477. Connection conn = null;
  478. ResultSet rs = null;
  479. try {
  480. conn = dataSource.getConnection();
  481. PreparedStatement ps = conn.prepareStatement(sb.toString());
  482. rs = ps.executeQuery();
  483. System.out.println("成功获取数据");
  484. String money = "";
  485. while (rs.next()){
  486. money = rs.getString("total");
  487. }
  488. resultJson.put("money", money);
  489. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  490. resultJson.toString());
  491. } catch (SQLException e) {
  492. // TODO Auto-generated catch block
  493. e.printStackTrace();
  494. } finally {
  495. try {
  496. if (conn != null) {
  497. conn.close();
  498. }
  499. } catch (SQLException e) {
  500. // TODO: handle exception
  501. }
  502. }
  503. return null;
  504. }
  505. // 个人消费明细-商家对账
  506. public String findConsume(){
  507. JSONObject resultJson = new JSONObject();
  508. StringBuilder sb = new StringBuilder();
  509. StringBuilder sb2 = new StringBuilder();
  510. if (this.build != null) {
  511. sb.append(" and b.build = '" + this.build + "' ");
  512. sb2.append(" and b.build = '" + this.build + "' ");
  513. }
  514. if (this.dom != null) {
  515. sb.append(" and b.dom = '" + this.dom + "' ");
  516. sb2.append(" and b.dom = '" + this.dom + "' ");
  517. }
  518. if (this.begin_time != null) {
  519. sb.append(" and a.begin_time > '" + this.begin_time + "' ");
  520. sb2.append(" and a.begin_time > '" + this.begin_time + "' ");
  521. }
  522. if (this.end_time != null ) {
  523. sb.append(" and a.begin_time < '" + this.end_time + "' ");
  524. sb2.append(" and a.begin_time < '" + this.end_time + "' ");
  525. }
  526. int total = this.waterService.findComTotal(sb2.toString());
  527. System.out.println(total);
  528. int start = (page - 1) * rows;// 每页的起始下标
  529. sb.append(" order by a.id desc limit "+start+", "+rows+";");
  530. List<Consume> pp = this.waterService.findCom(sb.toString());
  531. System.out.println(pp);
  532. if (pp == null) {
  533. resultJson.put("rows", "");
  534. resultJson.put("total", 0);
  535. } else {
  536. resultJson.put("rows", pp);
  537. // int total = listAll.size();
  538. resultJson.put("total", total);// 总记录数
  539. int totalPage = total % rows == 0 ? (total / rows)
  540. : (total / rows) + 1;// 总页数
  541. resultJson.put("totalPage", totalPage);
  542. resultJson.put("currentPage", page);// 当前页
  543. resultJson.put("numPerPage", rows);// 每页数
  544. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  545. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  546. resultJson.put("hasPreviousPage", true);// 有上一页
  547. resultJson.put("hasNextPage", true);// 有下一页
  548. resultJson.put("firstPage", true);// 首页
  549. resultJson.put("lastPage", true);// 尾页
  550. }
  551. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  552. return null;
  553. }
  554. // 日月年消费总额
  555. public String totalFeel(){
  556. JSONObject resultJson = new JSONObject();
  557. ApplicationContext ac = new ClassPathXmlApplicationContext(
  558. "applicationContext.xml");
  559. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  560. StringBuffer sb1 = new StringBuffer("select sum(a.use_amount) as total from consume a, build_water b where a.device_code=b.user_id and a.begin_time like '"+year+"%'");
  561. StringBuffer sb2 = new StringBuffer("select sum(a.use_amount) as total from consume a, build_water b where a.device_code=b.user_id and a.begin_time like '"+month+"%'");
  562. StringBuffer sb3 = new StringBuffer("select sum(a.use_amount) as total from consume a, build_water b where a.device_code=b.user_id and a.begin_time like '"+day+"%'");
  563. System.out.println(sb3.toString());
  564. if (this.build != null) {
  565. sb1.append(" and b.build = '" + this.build + "' ");
  566. sb2.append(" and b.build = '" + this.build + "' ");
  567. sb3.append(" and b.build = '" + this.build + "' ");
  568. }
  569. if (this.dom != null) {
  570. sb1.append(" and b.dom = '" + this.dom + "' ");
  571. sb2.append(" and b.dom = '" + this.dom + "' ");
  572. sb3.append(" and b.dom = '" + this.dom + "' ");
  573. }
  574. Connection conn = null;
  575. ResultSet rs1 = null;
  576. ResultSet rs2 = null;
  577. ResultSet rs3 = null;
  578. try {
  579. conn = dataSource.getConnection();
  580. PreparedStatement ps = conn.prepareStatement(sb1.toString());
  581. rs1 = ps.executeQuery();
  582. PreparedStatement ps2 = conn.prepareStatement(sb2.toString());
  583. rs2 = ps2.executeQuery();
  584. PreparedStatement ps3 = conn.prepareStatement(sb3.toString());
  585. rs3 = ps3.executeQuery();
  586. System.out.println("成功获取数据");
  587. String money1 = "";
  588. String money2 = "";
  589. String money3 = "";
  590. while (rs1.next()){
  591. money1 = rs1.getString("total");
  592. }
  593. while (rs2.next()){
  594. money2 = rs2.getString("total");
  595. }
  596. while (rs3.next()){
  597. money3 = rs3.getString("total");
  598. }
  599. System.out.println("money3: "+money3);
  600. resultJson.put("money_year", money1==""?"0":money1);
  601. resultJson.put("money_month", money2==""?"0":money2);
  602. resultJson.put("money_day", money3==""?"0":money3);
  603. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  604. resultJson.toString());
  605. } catch (SQLException e) {
  606. // TODO Auto-generated catch block
  607. e.printStackTrace();
  608. } finally {
  609. try {
  610. if (conn != null) {
  611. conn.close();
  612. }
  613. } catch (SQLException e) {
  614. // TODO: handle exception
  615. }
  616. }
  617. return null;
  618. }
  619. // 下拉列表-楼栋
  620. public String getBuilds(){
  621. JSONObject resultJson = new JSONObject();
  622. ApplicationContext ac = new ClassPathXmlApplicationContext(
  623. "applicationContext.xml");
  624. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  625. StringBuffer sb = new StringBuffer("select distinct build as build from build_water ");
  626. Connection conn = null;
  627. ResultSet rs = null;
  628. try {
  629. conn = dataSource.getConnection();
  630. PreparedStatement ps = conn.prepareStatement(sb.toString());
  631. rs = ps.executeQuery();
  632. System.out.println("成功获取数据");
  633. ArrayList al = new ArrayList();
  634. while (rs.next()){
  635. al.add(rs.getString("build"));
  636. }
  637. resultJson.put("builds", al);
  638. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  639. resultJson.toString());
  640. } catch (SQLException e) {
  641. // TODO Auto-generated catch block
  642. e.printStackTrace();
  643. } finally {
  644. try {
  645. if (conn != null) {
  646. conn.close();
  647. }
  648. } catch (SQLException e) {
  649. // TODO: handle exception
  650. }
  651. }
  652. return null;
  653. }
  654. // 下拉列表-宿舍
  655. public String getdoms(){
  656. JSONObject resultJson = new JSONObject();
  657. ApplicationContext ac = new ClassPathXmlApplicationContext(
  658. "applicationContext.xml");
  659. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  660. StringBuffer sb = new StringBuffer("select distinct dom as dom from build_water where 1=1 ");
  661. if (this.build != null){
  662. sb.append(" and build ='"+this.build + "'");
  663. }
  664. Connection conn = null;
  665. ResultSet rs = null;
  666. try {
  667. conn = dataSource.getConnection();
  668. PreparedStatement ps = conn.prepareStatement(sb.toString());
  669. rs = ps.executeQuery();
  670. System.out.println("成功获取数据");
  671. ArrayList al = new ArrayList();
  672. while (rs.next()){
  673. al.add(rs.getString("dom"));
  674. }
  675. resultJson.put("doms", al);
  676. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  677. resultJson.toString());
  678. } catch (SQLException e) {
  679. // TODO Auto-generated catch block
  680. e.printStackTrace();
  681. } finally {
  682. try {
  683. if (conn != null) {
  684. conn.close();
  685. }
  686. } catch (SQLException e) {
  687. // TODO: handle exception
  688. }
  689. }
  690. return null;
  691. }
  692. // 导出商家对账表格
  693. public String toComExcel(){
  694. JSONObject resultJson = new JSONObject();
  695. StringBuilder sb = new StringBuilder("select a.stu_number, a.user_name, a.use_amount, b.build, b.dom, a.begin_time from consume a, build_water b where a.device_code=b.user_id ");
  696. if (this.build != null) {
  697. sb.append(" and b.build = '" + this.build + "' ");
  698. }
  699. if (this.dom != null) {
  700. sb.append(" and b.dom = '" + this.dom + "' ");
  701. }
  702. if (this.begin_time != null) {
  703. sb.append(" and a.begin_time like '" + this.begin_time + "%' ");
  704. }
  705. sb.append(" order by a.id asc ");
  706. // 项目路径地址
  707. String path = request.getSession().getServletContext()
  708. .getRealPath("/download/");// File.separator
  709. ApplicationContext ac = new ClassPathXmlApplicationContext(
  710. "applicationContext.xml");
  711. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  712. Connection conn = null;
  713. ResultSet rs = null;
  714. try {
  715. conn = dataSource.getConnection();
  716. PreparedStatement ps = conn.prepareStatement(sb.toString());
  717. rs = ps.executeQuery();
  718. System.out.println("成功获取数据");
  719. Vector columnName = new Vector();
  720. columnName.add("学号");
  721. columnName.add("姓名");
  722. columnName.add("消费金额");
  723. columnName.add("楼栋");
  724. columnName.add("宿舍");
  725. columnName.add("消费时间");
  726. // 导出文件
  727. new DBtoExcel().WriteExcel(rs, path + "商家对账" + "Report.xls",
  728. "sheet1", columnName);
  729. ps.close();
  730. String url = request.getSession().getServletContext().getContextPath();
  731. System.out.println();
  732. resultJson.put("downurl", url+"/download/商家对账" + "Report.xls");
  733. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  734. resultJson.toString());
  735. } catch (SQLException e) {
  736. // TODO Auto-generated catch block
  737. e.printStackTrace();
  738. } finally {
  739. try {
  740. if (conn != null) {
  741. conn.close();
  742. }
  743. } catch (SQLException e) {
  744. // TODO: handle exception
  745. }
  746. }
  747. return null;
  748. }
  749. // 日用水统计
  750. public String dayTong(){
  751. List<String> dateList = new ArrayList<>();
  752. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  753. for (int i=0; i>-15; i--){
  754. Calendar calendar = Calendar.getInstance();
  755. calendar.add(Calendar.DATE,i);
  756. dateList.add(simpleDateFormat.format(calendar.getTime()));
  757. }
  758. JSONObject resultJson = new JSONObject();
  759. ApplicationContext ac = new ClassPathXmlApplicationContext(
  760. "applicationContext.xml");
  761. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  762. Connection conn = null;
  763. ResultSet rs = null;
  764. try {
  765. conn = dataSource.getConnection();
  766. ArrayList al = new ArrayList();
  767. for (int i=0; i<dateList.size(); i++) {
  768. StringBuffer sb = new StringBuffer("select sum(use_size) as use_size from `consume` a, build_water b where a.device_code=b.user_id and a.begin_time like '"+dateList.get(i)+"%' ");
  769. if (this.build != null) {
  770. sb.append(" and b.build = '" + this.build + "' ");
  771. }
  772. if (this.dom != null) {
  773. sb.append(" and b.dom = '" + this.dom + "' ");
  774. }
  775. PreparedStatement ps = conn.prepareStatement(sb.toString());
  776. rs = ps.executeQuery();
  777. while (rs.next()){
  778. if(rs.getString("use_size")==null || rs.getString("use_size").equals("null")) {
  779. al.add("0");
  780. }else{
  781. al.add(rs.getString("use_size"));
  782. }
  783. }
  784. }
  785. resultJson.put("day", dateList);
  786. resultJson.put("use_size", al);
  787. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  788. resultJson.toString());
  789. } catch (SQLException e) {
  790. // TODO Auto-generated catch block
  791. e.printStackTrace();
  792. } finally {
  793. try {
  794. if (conn != null) {
  795. conn.close();
  796. }
  797. } catch (SQLException e) {
  798. // TODO: handle exception
  799. }
  800. }
  801. return null;
  802. }
  803. // 月用水统计
  804. public String monthTong(){
  805. List<String> dateList = new ArrayList<>();
  806. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
  807. for (int i=0; i>-15; i--){
  808. Calendar calendar = Calendar.getInstance();
  809. calendar.add(Calendar.MONTH,i);
  810. dateList.add(simpleDateFormat.format(calendar.getTime()));
  811. }
  812. JSONObject resultJson = new JSONObject();
  813. ApplicationContext ac = new ClassPathXmlApplicationContext(
  814. "applicationContext.xml");
  815. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  816. Connection conn = null;
  817. ResultSet rs = null;
  818. try {
  819. conn = dataSource.getConnection();
  820. ArrayList al = new ArrayList();
  821. for (int i=0; i<dateList.size(); i++) {
  822. StringBuffer sb = new StringBuffer("select sum(use_size) as use_size from `consume` a, build_water b where a.device_code=b.user_id and a.begin_time like '"+dateList.get(i)+"%' ");
  823. if (this.build != null) {
  824. sb.append(" and b.build = '" + this.build + "' ");
  825. }
  826. if (this.dom != null) {
  827. sb.append(" and b.dom = '" + this.dom + "' ");
  828. }
  829. PreparedStatement ps = conn.prepareStatement(sb.toString());
  830. rs = ps.executeQuery();
  831. while (rs.next()){
  832. if(rs.getString("use_size")==null || rs.getString("use_size").equals("null")) {
  833. al.add("0");
  834. }else{
  835. al.add(rs.getString("use_size"));
  836. }
  837. }
  838. }
  839. resultJson.put("month", dateList);
  840. resultJson.put("use_size", al);
  841. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  842. resultJson.toString());
  843. } catch (SQLException e) {
  844. // TODO Auto-generated catch block
  845. e.printStackTrace();
  846. } finally {
  847. try {
  848. if (conn != null) {
  849. conn.close();
  850. }
  851. } catch (SQLException e) {
  852. // TODO: handle exception
  853. }
  854. }
  855. return null;
  856. }
  857. // 年用水统计
  858. public String yearTong(){
  859. List<String> dateList = new ArrayList<>();
  860. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
  861. for (int i=0; i>-15; i--){
  862. Calendar calendar = Calendar.getInstance();
  863. calendar.add(Calendar.YEAR, i);
  864. dateList.add(simpleDateFormat.format(calendar.getTime()));
  865. }
  866. JSONObject resultJson = new JSONObject();
  867. ApplicationContext ac = new ClassPathXmlApplicationContext(
  868. "applicationContext.xml");
  869. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  870. Connection conn = null;
  871. ResultSet rs = null;
  872. try {
  873. conn = dataSource.getConnection();
  874. ArrayList al = new ArrayList();
  875. for (int i=0; i<dateList.size(); i++) {
  876. StringBuffer sb = new StringBuffer("select sum(use_size) as use_size from `consume` a, build_water b where a.device_code=b.user_id and a.begin_time like '"+dateList.get(i)+"%' ");
  877. if (this.build != null) {
  878. sb.append(" and b.build = '" + this.build + "' ");
  879. }
  880. if (this.dom != null) {
  881. sb.append(" and b.dom = '" + this.dom + "' ");
  882. }
  883. PreparedStatement ps = conn.prepareStatement(sb.toString());
  884. rs = ps.executeQuery();
  885. while (rs.next()){
  886. if(rs.getString("use_size")==null || rs.getString("use_size").equals("null")) {
  887. al.add("0");
  888. }else{
  889. al.add(rs.getString("use_size"));
  890. }
  891. }
  892. }
  893. resultJson.put("year", dateList);
  894. resultJson.put("use_size", al);
  895. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  896. resultJson.toString());
  897. } catch (SQLException e) {
  898. // TODO Auto-generated catch block
  899. e.printStackTrace();
  900. } finally {
  901. try {
  902. if (conn != null) {
  903. conn.close();
  904. }
  905. } catch (SQLException e) {
  906. // TODO: handle exception
  907. }
  908. }
  909. return null;
  910. }
  911. // 用水总量
  912. public String waterTotal(){
  913. JSONObject resultJson = new JSONObject();
  914. ApplicationContext ac = new ClassPathXmlApplicationContext(
  915. "applicationContext.xml");
  916. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  917. StringBuffer sb = new StringBuffer("select sum(use_size) as total from consume a, build_water b where a.device_code=b.user_id ");
  918. if (this.build != null) {
  919. sb.append(" and b.build = '" + this.build + "' ");
  920. }
  921. if (this.dom != null) {
  922. sb.append(" and b.dom = '" + this.dom + "' ");
  923. }
  924. Connection conn = null;
  925. ResultSet rs = null;
  926. try {
  927. conn = dataSource.getConnection();
  928. PreparedStatement ps = conn.prepareStatement(sb.toString());
  929. rs = ps.executeQuery();
  930. System.out.println("成功获取数据");
  931. String size = "";
  932. while (rs.next()){
  933. if(rs.getString("total")==null || rs.getString("total").equals("null")) {
  934. size = "0";
  935. }else{
  936. size = rs.getString("total");
  937. }
  938. }
  939. resultJson.put("size", size);
  940. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  941. resultJson.toString());
  942. } catch (SQLException e) {
  943. // TODO Auto-generated catch block
  944. e.printStackTrace();
  945. } finally {
  946. try {
  947. if (conn != null) {
  948. conn.close();
  949. }
  950. } catch (SQLException e) {
  951. // TODO: handle exception
  952. }
  953. }
  954. return null;
  955. }
  956. // 用水分析-用水详情
  957. public String detailWater(){
  958. JSONObject resultJson = new JSONObject();
  959. StringBuilder sb = new StringBuilder();
  960. StringBuilder sb2 = new StringBuilder();
  961. if (this.build != null) {
  962. sb.append(" and b.build = '" + this.build + "' ");
  963. sb2.append(" and b.build = '" + this.build + "' ");
  964. }
  965. if (this.dom != null) {
  966. sb.append(" and b.dom = '" + this.dom + "' ");
  967. sb2.append(" and b.dom = '" + this.dom + "' ");
  968. }
  969. if (this.username != null){
  970. sb.append(" and a.user_name = '" + this.username + "' ");
  971. sb2.append(" and a.user_name = '" + this.username + "' ");
  972. }
  973. int total = this.waterService.findComTotal(sb2.toString());
  974. System.out.println(total);
  975. int start = (page - 1) * rows;// 每页的起始下标
  976. sb.append(" order by a.id asc limit "+start+", "+rows+";");
  977. List<Consume> pp = this.waterService.findCom(sb.toString());
  978. System.out.println(pp);
  979. if (pp == null) {
  980. resultJson.put("rows", "");
  981. resultJson.put("total", 0);
  982. } else {
  983. resultJson.put("rows", pp);
  984. // int total = listAll.size();
  985. resultJson.put("total", total);// 总记录数
  986. int totalPage = total % rows == 0 ? (total / rows)
  987. : (total / rows) + 1;// 总页数
  988. resultJson.put("totalPage", totalPage);
  989. resultJson.put("currentPage", page);// 当前页
  990. resultJson.put("numPerPage", rows);// 每页数
  991. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  992. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  993. resultJson.put("hasPreviousPage", true);// 有上一页
  994. resultJson.put("hasNextPage", true);// 有下一页
  995. resultJson.put("firstPage", true);// 首页
  996. resultJson.put("lastPage", true);// 尾页
  997. }
  998. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  999. return null;
  1000. }
  1001. // 修改费率
  1002. public String updatePrice(){
  1003. JSONObject json = new JSONObject();
  1004. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1005. String time = sf.format(new Date());
  1006. Price price = new Price();
  1007. price.setPrice(rate);
  1008. price.setName("热水");
  1009. price.setState(1);
  1010. price.setTime(time);
  1011. price.setTime2("至今");
  1012. int m = waterService.passPrice(time);
  1013. int n = waterService.insertPrice(price);
  1014. if (m >0 & n>0){
  1015. json.put("msg", "修改成功");
  1016. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1017. }
  1018. return null;
  1019. }
  1020. public List<Price> queryPrice(){
  1021. JSONObject resultJson = new JSONObject();
  1022. List<Price> listPage = waterService.queryPrice(page, rows);// 查询分页
  1023. int total = waterService.findPriceTotal();// 查询表中的总记录数
  1024. if (listPage == null) {
  1025. resultJson.put("rows", "");
  1026. resultJson.put("total", 0);
  1027. } else {
  1028. resultJson.put("rows", listPage);
  1029. // int total = listAll.size();
  1030. resultJson.put("total", total);// 总记录数
  1031. int totalPage = total % rows == 0 ? (total / rows)
  1032. : (total / rows) + 1;// 总页数
  1033. resultJson.put("totalPage", totalPage);
  1034. resultJson.put("currentPage", page);// 当前页
  1035. resultJson.put("numPerPage", rows);// 每页数
  1036. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  1037. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  1038. resultJson.put("hasPreviousPage", true);// 有上一页
  1039. resultJson.put("hasNextPage", true);// 有下一页
  1040. resultJson.put("firstPage", true);// 首页
  1041. resultJson.put("lastPage", true);// 尾页
  1042. }
  1043. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  1044. resultJson.toString());
  1045. return null;
  1046. }
  1047. // 当前费率
  1048. public String currentRate(){
  1049. JSONObject resultJson = new JSONObject();
  1050. ApplicationContext ac = new ClassPathXmlApplicationContext(
  1051. "applicationContext.xml");
  1052. DataSource dataSource = (DataSource) ac.getBean("slaveDataSource");
  1053. StringBuffer sb = new StringBuffer("select price from price where name='热水' and state=1 and time in (select MAX(time) from `price` where name='热水' and state=1) ");
  1054. Connection conn = null;
  1055. ResultSet rs = null;
  1056. try {
  1057. conn = dataSource.getConnection();
  1058. PreparedStatement ps = conn.prepareStatement(sb.toString());
  1059. rs = ps.executeQuery();
  1060. System.out.println("成功获取数据");
  1061. String rate = "";
  1062. while (rs.next()){
  1063. rate = rs.getString("price");
  1064. }
  1065. resultJson.put("rate", rate);
  1066. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  1067. resultJson.toString());
  1068. } catch (SQLException e) {
  1069. // TODO Auto-generated catch block
  1070. e.printStackTrace();
  1071. } finally {
  1072. try {
  1073. if (conn != null) {
  1074. conn.close();
  1075. }
  1076. } catch (SQLException e) {
  1077. // TODO: handle exception
  1078. }
  1079. }
  1080. return null;
  1081. }
  1082. public String queryAdmin(){
  1083. JSONObject resultJson = new JSONObject();
  1084. String s1 = "";
  1085. if (number!=null){
  1086. s1 = " and number='"+this.number+"'";
  1087. }
  1088. List<Admin> listPage = waterService.queryAdmin(page, rows, s1); // 查询分页
  1089. int total = waterService.findAdminTotal(s1); // 查询表中的总记录数
  1090. if (listPage == null) {
  1091. resultJson.put("rows", "");
  1092. resultJson.put("total", 0);
  1093. } else {
  1094. resultJson.put("rows", listPage);
  1095. // int total = listAll.size();
  1096. resultJson.put("total", total);// 总记录数
  1097. int totalPage = total % rows == 0 ? (total / rows)
  1098. : (total / rows) + 1;// 总页数
  1099. resultJson.put("totalPage", totalPage);
  1100. resultJson.put("currentPage", page);// 当前页
  1101. resultJson.put("numPerPage", rows);// 每页数
  1102. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  1103. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  1104. resultJson.put("hasPreviousPage", true);// 有上一页
  1105. resultJson.put("hasNextPage", true);// 有下一页
  1106. resultJson.put("firstPage", true);// 首页
  1107. resultJson.put("lastPage", true);// 尾页
  1108. }
  1109. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  1110. resultJson.toString());
  1111. return null;
  1112. }
  1113. public String addAdmin(){
  1114. JSONObject json = new JSONObject();
  1115. List<Admin> ad = waterService.queryAdminByNum(number);
  1116. if (ad!=null){
  1117. json.put("msg", "用户已存在");
  1118. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1119. return null;
  1120. }
  1121. Admin admin = new Admin();
  1122. admin.setName(name);
  1123. admin.setNumber(number);
  1124. admin.setPassword(password);
  1125. int m = waterService.addAdmin(admin);
  1126. if (m>0){
  1127. json.put("msg", "添加成功");
  1128. }
  1129. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1130. return null;
  1131. }
  1132. public String delAdmin(){
  1133. JSONObject json = new JSONObject();
  1134. int m = this.waterService.delAdmin(id);
  1135. if (m>0){
  1136. json.put("msg", "删除成功");
  1137. }
  1138. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1139. return null;
  1140. }
  1141. public String updateAdmin(){
  1142. JSONObject json = new JSONObject();
  1143. Admin admin = new Admin();
  1144. System.out.println(id);
  1145. admin.setId(id);
  1146. admin.setName(name);
  1147. admin.setPassword(password);
  1148. admin.setNumber(number);
  1149. int m = waterService.updateAdmin(admin);
  1150. if (m>0){
  1151. json.put("msg", "更新成功");
  1152. }
  1153. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1154. return null;
  1155. }
  1156. public String login(){
  1157. JSONObject json = new JSONObject();
  1158. List<Admin> login = waterService.login(number, password);
  1159. if (login==null){
  1160. json.put("state", "0");
  1161. json.put("msg", "用户名或密码不正确");
  1162. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1163. return null;
  1164. }
  1165. json.put("state", "1");
  1166. json.put("msg", "登录成功");
  1167. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1168. return null;
  1169. }
  1170. // 查看水费异常充值记录
  1171. public String findErrorPayByNo(){
  1172. JSONObject resultJson = new JSONObject();
  1173. List<Recharge> lrs = waterService.findErrorPayByNo(page, rows);
  1174. int total = waterService.findErrorPayTotal();
  1175. if (lrs == null) {
  1176. resultJson.put("rows", "");
  1177. resultJson.put("total", 0);
  1178. } else {
  1179. resultJson.put("rows", lrs);
  1180. // int total = listAll.size();
  1181. resultJson.put("total", total);// 总记录数
  1182. int totalPage = total % rows == 0 ? (total / rows)
  1183. : (total / rows) + 1;// 总页数
  1184. resultJson.put("totalPage", totalPage);
  1185. resultJson.put("currentPage", page);// 当前页
  1186. resultJson.put("numPerPage", rows);// 每页数
  1187. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  1188. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  1189. resultJson.put("hasPreviousPage", true);// 有上一页
  1190. resultJson.put("hasNextPage", true);// 有下一页
  1191. resultJson.put("firstPage", true);// 首页
  1192. resultJson.put("lastPage", true);// 尾页
  1193. }
  1194. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  1195. resultJson.toString());
  1196. return null;
  1197. }
  1198. // 处理水费异常充值
  1199. public String handlerPayError(){
  1200. JSONObject json = new JSONObject();
  1201. int m = waterService.updateErrorWaterPay(id);
  1202. if (m>0){
  1203. json.put("code", 1);
  1204. json.put("msg", "处理成功");
  1205. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1206. return null;
  1207. }
  1208. json.put("code", 0);
  1209. json.put("msg", "处理失败");
  1210. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1211. return null;
  1212. }
  1213. // 查看电费异常充值记录
  1214. public String findErrorElcPayByNo(){
  1215. JSONObject resultJson = new JSONObject();
  1216. List<Recharge_elc> lrs = waterService.findErrorElcPayByNo(page, rows);
  1217. int total = waterService.findErrorElecTotal();
  1218. if (lrs == null) {
  1219. resultJson.put("rows", "");
  1220. resultJson.put("total", 0);
  1221. } else {
  1222. resultJson.put("rows", lrs);
  1223. // int total = listAll.size();
  1224. resultJson.put("total", total);// 总记录数
  1225. int totalPage = total % rows == 0 ? (total / rows)
  1226. : (total / rows) + 1;// 总页数
  1227. resultJson.put("totalPage", totalPage);
  1228. resultJson.put("currentPage", page);// 当前页
  1229. resultJson.put("numPerPage", rows);// 每页数
  1230. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  1231. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  1232. resultJson.put("hasPreviousPage", true);// 有上一页
  1233. resultJson.put("hasNextPage", true);// 有下一页
  1234. resultJson.put("firstPage", true);// 首页
  1235. resultJson.put("lastPage", true);// 尾页
  1236. }
  1237. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  1238. resultJson.toString());
  1239. return null;
  1240. }
  1241. // 处理电费异常充值
  1242. public String handlerElecPayError(){
  1243. JSONObject json = new JSONObject();
  1244. int m = waterService.updateErrorElecPay(id);
  1245. if (m>0){
  1246. json.put("code", 1);
  1247. json.put("msg", "处理成功");
  1248. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1249. return null;
  1250. }
  1251. json.put("code", 0);
  1252. json.put("msg", "处理失败");
  1253. ResponseUtil.writeJson(ServletActionContext.getResponse(), json.toString());
  1254. return null;
  1255. }
  1256. // 查看异常水费
  1257. public String queryErrorWater(){
  1258. JSONObject resultJson = new JSONObject();
  1259. StringBuffer s1 = new StringBuffer();
  1260. StringBuffer s2 = new StringBuffer();
  1261. StringBuffer s3 = new StringBuffer();
  1262. if (build!=null){
  1263. s1.append(" and b.build='"+this.build+"' ");
  1264. }
  1265. if (begin_time!=null){
  1266. s1.append(" and a.begin_time>'"+this.begin_time+"' ");
  1267. }
  1268. if (end_time!=null){
  1269. s1.append(" and a.begin_time<'"+this.end_time+"' ");
  1270. }
  1271. if (use_amount!=null){
  1272. s2.append(" and a.use_amount<"+this.use_amount);
  1273. }
  1274. if (use_amount!=null){
  1275. s3.append(" and a.use_amount<"+this.use_amount);
  1276. }
  1277. int total = waterService.queryErrorwaterTotal(s1.toString(), s3.toString());
  1278. int start = (page - 1) * rows;// 每页的起始下标
  1279. s2.append(" limit "+start+", "+rows+";");
  1280. List<ErrorWaterPay> pp = this.waterService.queryErrorPay(s1.toString(), s2.toString());
  1281. System.out.println(pp);
  1282. if (pp == null) {
  1283. resultJson.put("rows", "");
  1284. resultJson.put("total", 0);
  1285. } else {
  1286. resultJson.put("rows", pp);
  1287. // int total = listAll.size();
  1288. resultJson.put("total", total);// 总记录数
  1289. int totalPage = total % rows == 0 ? (total / rows)
  1290. : (total / rows) + 1;// 总页数
  1291. resultJson.put("totalPage", totalPage);
  1292. resultJson.put("currentPage", page);// 当前页
  1293. resultJson.put("numPerPage", rows);// 每页数
  1294. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  1295. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  1296. resultJson.put("hasPreviousPage", true);// 有上一页
  1297. resultJson.put("hasNextPage", true);// 有下一页
  1298. resultJson.put("firstPage", true);// 首页
  1299. resultJson.put("lastPage", true);// 尾页
  1300. }
  1301. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  1302. return null;
  1303. }
  1304. // 根据水表ID查宿舍
  1305. public String queryDom(){
  1306. JSONObject resultJson = new JSONObject();
  1307. if (user_id==null){
  1308. resultJson.put("msg", "无水表id");
  1309. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  1310. return null;
  1311. }
  1312. System.out.println(user_id);
  1313. String sqlx = " and user_id in ( '" + user_id.replaceAll(",", "','") +"')";
  1314. System.out.println(sqlx);
  1315. List<Build_water> bw = waterService.queryByUserId(sqlx);
  1316. resultJson.put("msg", "获取成功");
  1317. resultJson.put("data", bw);
  1318. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  1319. return null;
  1320. }
  1321. public String queryRe(){
  1322. JSONObject resultJson = new JSONObject();
  1323. StringBuilder sql = new StringBuilder("select * from `recharge` where pay_state=2 ");
  1324. StringBuilder sql2 = new StringBuilder("select count(*) from `recharge` where pay_state=2 ");
  1325. StringBuilder sql3 = new StringBuilder("select sum(account) from `recharge` where pay_state=2 ");
  1326. StringBuilder sql4 = new StringBuilder("select AVG(account) from `recharge` where pay_state=2 ");
  1327. if (begin_time != null ){
  1328. sql.append(" and re_time > '"+begin_time+"'");
  1329. sql2.append(" and re_time > '"+begin_time+"'");
  1330. sql3.append(" and re_time > '"+begin_time+"'");
  1331. sql4.append(" and re_time > '"+begin_time+"'");
  1332. }
  1333. if (end_time != null ){
  1334. sql.append(" and re_time < '"+end_time+" 24:60:60'");
  1335. sql2.append(" and re_time < '"+end_time+" 24:60:60'");
  1336. sql3.append(" and re_time < '"+end_time+" 24:60:60'");
  1337. sql4.append(" and re_time < '"+end_time+" 24:60:60'");
  1338. }
  1339. System.out.println(sql);
  1340. if (user_name != null ){
  1341. sql.append(" and user_name like '"+user_name+"%'");
  1342. sql2.append(" and user_name like '"+user_name+"%'");
  1343. sql3.append(" and user_name like '"+user_name+"%'");
  1344. sql4.append(" and user_name like '"+user_name+"%'");
  1345. }
  1346. int total = waterService.queryReTotal(sql2.toString());
  1347. long totalAccount = waterService.queryReOther(sql3.toString());
  1348. long avgAccount = waterService.queryReOther(sql4.toString());
  1349. int start = (page - 1) * rows;// 每页的起始下标
  1350. sql.append(" limit "+start+", "+rows+";");
  1351. List<Recharge> pp = this.waterService.queryByTime(sql.toString());
  1352. System.out.println(pp);
  1353. if (pp == null) {
  1354. resultJson.put("rows", "");
  1355. resultJson.put("total", 0);
  1356. } else {
  1357. resultJson.put("rows", pp);
  1358. // int total = listAll.size();
  1359. resultJson.put("total", total);// 总记录数
  1360. int totalPage = total % rows == 0 ? (total / rows)
  1361. : (total / rows) + 1;// 总页数
  1362. resultJson.put("totalPage", totalPage);
  1363. resultJson.put("totalAccount", totalAccount);
  1364. resultJson.put("avgAccount", avgAccount);
  1365. resultJson.put("currentPage", page);// 当前页
  1366. resultJson.put("numPerPage", rows);// 每页数
  1367. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  1368. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  1369. resultJson.put("hasPreviousPage", true);// 有上一页
  1370. resultJson.put("hasNextPage", true);// 有下一页
  1371. resultJson.put("firstPage", true);// 首页
  1372. resultJson.put("lastPage", true);// 尾页
  1373. }
  1374. ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  1375. return null;
  1376. }
  1377. }