IndexAction.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package com.happy.action;
  2. import com.happy.Model.Admin;
  3. import com.happy.Model.TreMenu;
  4. import com.happy.Model.TwoMenu;
  5. import com.happy.service.OneMenuService;
  6. import com.happy.service.TreMenuService;
  7. import com.happy.service.TwoMenuService;
  8. import com.happy.unitil.ResponseUtil;
  9. import com.opensymphony.xwork2.ActionSupport;
  10. import net.sf.json.JSONArray;
  11. import net.sf.json.JSONObject;
  12. import org.apache.struts2.ServletActionContext;
  13. import org.apache.struts2.interceptor.ServletRequestAware;
  14. import org.springframework.stereotype.Controller;
  15. import javax.annotation.Resource;
  16. import javax.servlet.http.HttpServletRequest;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. /**
  20. * 首页action
  21. *
  22. * @author zjs
  23. *
  24. */
  25. @Controller
  26. public class IndexAction extends ActionSupport implements ServletRequestAware {
  27. private HttpServletRequest request;
  28. public HttpServletRequest getRequest() {
  29. return request;
  30. }
  31. public void setRequest(HttpServletRequest request) {
  32. this.request = request;
  33. }
  34. @Resource
  35. private OneMenuService oneMenuService;
  36. @Resource
  37. private TwoMenuService twoMenuService;
  38. @Resource
  39. private TreMenuService treMenuService;
  40. public TreMenuService getTreMenuService() {
  41. return treMenuService;
  42. }
  43. public void setTreMenuService(TreMenuService treMenuService) {
  44. this.treMenuService = treMenuService;
  45. }
  46. public TwoMenuService getTwoMenuService() {
  47. return twoMenuService;
  48. }
  49. public void setTwoMenuService(TwoMenuService twoMenuService) {
  50. this.twoMenuService = twoMenuService;
  51. }
  52. public OneMenuService getOneMenuService() {
  53. return oneMenuService;
  54. }
  55. public void setOneMenuService(OneMenuService oneMenuService) {
  56. this.oneMenuService = oneMenuService;
  57. }
  58. public void setServletRequest(HttpServletRequest request) {
  59. this.request = request;
  60. }
  61. private Integer pid;
  62. private int id;
  63. private String uuid;
  64. private String[] order_account;
  65. public String[] getOrder_account() {
  66. return order_account;
  67. }
  68. public void setOrder_account(String[] order_account) {
  69. this.order_account = order_account;
  70. }
  71. public String getUuid() {
  72. return uuid;
  73. }
  74. public void setUuid(String uuid) {
  75. this.uuid = uuid;
  76. }
  77. public int getId() {
  78. return id;
  79. }
  80. public void setId(int id) {
  81. this.id = id;
  82. }
  83. public Integer getPid() {
  84. return pid;
  85. }
  86. public void setPid(Integer pid) {
  87. this.pid = pid;
  88. }
  89. /*
  90. * //一级菜单 public String oneMenu() throws Exception{ //从session获取admin_id
  91. * Admin admin=(Admin)
  92. * ServletActionContext.getRequest().getSession().getAttribute("admin");
  93. * String isLogin = (String)
  94. * ServletActionContext.getRequest().getSession().getAttribute("isLogin");
  95. * //System.out.println(isLogin); JSONObject resultJson = new JSONObject();
  96. * List<OneMenu> list = oneMenuService.getOneMenuList();
  97. * resultJson.put("menu",list);
  98. * ResponseUtil.writeJson(ServletActionContext.getResponse
  99. * (),resultJson.toString()); // System.out.println(resultJson); return
  100. * null; }
  101. */
  102. // 二级菜单
  103. public String twoMenu() throws Exception {
  104. Admin admin = (Admin) ServletActionContext.getRequest().getSession()
  105. .getAttribute("admin");
  106. if (admin != null) {
  107. if (admin.getLevel() == 1) { // 超级管理员默认查询当前一级菜单的所有二级菜单
  108. JSONObject json = new JSONObject();
  109. List<TwoMenu> l = twoMenuService.getTwoMenu1(pid);
  110. // List<List<TwoMenu>> list = new ArrayList<List<TwoMenu>>();
  111. // list.add(l);
  112. /*
  113. * int len=l.size()-1;//最大下标 String twomenu="["; for(int
  114. * i=0;i<l.size();i++){ if(i==len){ twomenu+="{"+l.get(i)+"}";
  115. * }else{ twomenu+="{"+l.get(i)+"},"; } } twomenu+="]";
  116. */
  117. JSONArray listArray = JSONArray.fromObject(l);
  118. // JSONObject jsonOb = JSONObject.fromObject(listArray);
  119. ResponseUtil.write(listArray,
  120. ServletActionContext.getResponse());
  121. }
  122. }
  123. return null;
  124. }
  125. // 三级菜单
  126. public String treMenu() throws Exception {
  127. Admin admin = (Admin) ServletActionContext.getRequest().getSession()
  128. .getAttribute("admin");
  129. if (admin != null) {
  130. if (admin.getLevel() == 1) { // 超级管理员默认查询当前二级菜单的所有二级菜单
  131. List<TreMenu> l = treMenuService.getTreMenu(pid);
  132. JSONArray listArray = JSONArray.fromObject(l);
  133. // json.put("level", 10);
  134. ResponseUtil.write(listArray,
  135. ServletActionContext.getResponse());
  136. }
  137. }
  138. return null;
  139. }
  140. // 树形菜单
  141. public String tree() throws Exception {
  142. int pid[] = { 1, 2, 3, 4, 5 };// 所有一级
  143. // JSONObject json = new JSONObject();
  144. List<List<TwoMenu>> list = new ArrayList<List<TwoMenu>>();
  145. String msg = "";
  146. for (int i = 0; i < pid.length; i++) {
  147. List<TwoMenu> l = twoMenuService.getTwoMenu1(pid[i]);
  148. for (int j = 0; j < l.size(); j++) {
  149. JSONObject js1 = JSONObject.fromObject(l.get(j));
  150. String m = js1.toString();
  151. m = m.substring(0, m.length() - 1) + ",children:[";
  152. List<TreMenu> l1 = treMenuService.getTreMenu(l.get(j).getId());
  153. for (int k = 0; k < l1.size(); k++) {
  154. JSONObject js2 = JSONObject.fromObject(l1.get(k));
  155. m = m + js2.toString() + ",";
  156. }
  157. m = m.substring(0, m.length() - 1) + "]},";
  158. msg = msg + m;
  159. }
  160. }
  161. msg = "[" + msg.substring(0, msg.length() - 1) + "]";
  162. // JSONObject jss = new JSONObject(msg);
  163. // System.out.println(msg);
  164. // json.put("success", true);
  165. ResponseUtil.write(msg, ServletActionContext.getResponse());
  166. return null;
  167. }
  168. /*
  169. * public String info() throws Exception{ if(uuid!=null){ return "info"; }
  170. * return null; } /*public String select()throws Exception{ if(id!=0){
  171. * System.out.println(id); } JSONObject json = new JSONObject();
  172. * json.put("carton_type", "对口箱"); json.put("model_name", "对口箱1");
  173. * json.put("carton_length", "58"); json.put("carton_width", "54");
  174. * json.put("carton_height", "53"); json.put("spec_type", "制造尺寸");
  175. * json.put("material_science", "B636B"); json.put("pit_type", "BC");
  176. * json.put("carton_color", "灰白"); json.put("pack_num", "50");
  177. * json.put("line_type", "外压"); json.put("fabric_width", "20");
  178. * json.put("isnail", "是"); json.put("isviscose", "否"); //String msg =
  179. * "[{\"iconCls\": \"closed\", \"id\": 201, \"level\": \"1\", \"pid\": 1, \"state\": \"colos\", \"text\": \"物资损耗管理 \", \"url\": \"\"}]"
  180. * ; ResponseUtil.write(json, ServletActionContext.getResponse()); return
  181. * null; } public String test() throws Exception{ JSONObject json = new
  182. * JSONObject(); json.put("msg", 1);
  183. *
  184. * System.out.println(uuid); ResponseUtil.write(json,
  185. * ServletActionContext.getResponse()); return null; }
  186. */
  187. }