Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.15 KB | None | 0 0
  1. package com.booking.business.web;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Set;
  7.  
  8. import net.sf.json.JSONArray;
  9. import net.sf.json.JSONObject;
  10.  
  11. import com.opensymphony.xwork2.ActionContext;
  12. import com.opensymphony.xwork2.ActionSupport;
  13. import com.booking.business.service.IAnnounceService;
  14. import com.booking.business.service.IServicesService;
  15. import com.booking.business.service.IStoreService;
  16. import com.booking.business.service.ITimetableService;
  17. import com.booking.business.service.IUserService;
  18. import com.booking.domain.Announce;
  19. import com.booking.domain.BookingOrder;
  20. import com.booking.domain.Services;
  21. import com.booking.domain.Store;
  22. import com.booking.domain.Timetable;
  23. import com.booking.domain.User;
  24.  
  25. public class StoreManageAction extends ActionSupport{
  26.  
  27. protected IStoreService storeService;
  28. protected IUserService userService;
  29. protected IAnnounceService announceService;
  30. protected IServicesService servicesService;
  31. protected ITimetableService timetableService;
  32.  
  33. private Integer storeId;
  34. private String storename;
  35. // private String brief;
  36. private String address;
  37. private Integer announceId;
  38. private String userId;
  39. private String openId;
  40. private HashMap<String, Object> resultMap = new HashMap<String, Object>();
  41.  
  42.  
  43. public String manageStore() throws Exception{
  44. ActionContext ctx = ActionContext.getContext();
  45. String openId = (String) ctx.get("openId");
  46. Store store = userService.getUser(openId).getStore();
  47. Set<Timetable> timelist = store.getTimetables();
  48. System.out.println(timelist.size());
  49. ctx.put("store", store);
  50. ctx.put("timelist", timelist);
  51. return "manageStore";
  52. }
  53.  
  54. public String addStore() throws Exception{
  55. resultMap = new HashMap<String, Object>();
  56. storeService.addStore(storename, address, userService.getUser(openId));
  57. resultMap.put("status", true);
  58. resultMap.put("msg", "保存成功");
  59. return SUCCESS;
  60. }
  61.  
  62.  
  63. public String listStore() throws Exception{
  64. List<Store> list = storeService.listStore();
  65. ActionContext ctx = ActionContext.getContext();
  66. ctx.put("list", list);
  67. return "listStore";
  68. }
  69.  
  70. public String listOrders() throws Exception{
  71. Set<BookingOrder> list = storeService.getStore(storeId).getOrders();
  72. ActionContext ctx = ActionContext.getContext();
  73. ctx.put("list", list);
  74. return "listOrders";
  75. }
  76.  
  77. public String listServices() throws Exception{
  78. Set<Services> list = storeService.getStore(storeId).getServices();
  79. ActionContext ctx = ActionContext.getContext();
  80. ctx.put("list", list);
  81. return "listServices";
  82. }
  83.  
  84. // 前端接口
  85. public String outwardAdminNavigation() throws Exception{
  86. return "outwardAdminNavigation";
  87. }
  88.  
  89.  
  90. /*
  91. * 列出所有商店
  92. * @param openId
  93. */
  94. public String outwardStoreList() throws Exception{
  95. ActionContext ctx = ActionContext.getContext();
  96. List<Store> list = storeService.listStore();
  97. ctx.put("list", list);
  98. return "outwardStoreList";
  99. }
  100.  
  101. /*
  102. * 查看商店信息
  103. *
  104. */
  105. public String outwardViewStore() throws Exception{
  106. ActionContext ctx = ActionContext.getContext();
  107. String openId = (String) ctx.get("openId");
  108. ctx.put("store", storeService.getStore(storeId));
  109. return "outwardViewStore";
  110. }
  111.  
  112.  
  113. /*
  114. * 列出我的商店的订单
  115. * @param openId
  116. */
  117. public String outwardStoreListOrders() throws Exception{
  118. ActionContext ctx = ActionContext.getContext();
  119. String openId = (String) ctx.get("openId");
  120. Set<BookingOrder> list = userService.getUser(openId).getStore().getOrders();
  121. ctx.put("list", list);
  122. return "outwardStoreListOrders";
  123. }
  124. /*
  125. * 列出我的商店的公告
  126. * @param openId
  127. */
  128. public String outwardStoreListAnnounce() throws Exception{
  129. ActionContext ctx = ActionContext.getContext();
  130. String openId = (String) ctx.get("openId");
  131. Set<Announce> list = userService.getUser(openId).getStore().getAnnounces();
  132. ctx.put("list", list);
  133. return "outwardStoreListAnnounce";
  134. }
  135.  
  136. /*
  137. * 公告具体
  138. */
  139. public String outwardStoreViewAnnounce() throws Exception{
  140. ActionContext ctx = ActionContext.getContext();
  141. Announce announce = announceService.getAnnounce(announceId);
  142. ctx.put("announce", announce);
  143. return "outwardStoreViewAnnounce";
  144. }
  145. /*
  146. * 列出服务项目
  147. * @param storeId
  148. */
  149. public String outwardListServices() throws Exception{
  150. ActionContext ctx = ActionContext.getContext();
  151. String openId = (String) ctx.get("openId");
  152. Store store = userService.getUser(openId).getStore();
  153. ctx.put("list", store.getServices());
  154. return "outwardListServices";
  155. }
  156.  
  157.  
  158. /*
  159. * 商店时间列表
  160. * @param openId
  161. */
  162. public String outwardListTime() throws Exception{
  163. ActionContext ctx = ActionContext.getContext();
  164. resultMap = new HashMap<String, Object>();
  165. String openId = (String) ctx.get("openId");
  166.  
  167. Store store = userService.getUser(openId).getStore();
  168.  
  169. ctx.put("listTime", timetableService.getTimetables(store));
  170. return "outwardListTime";
  171. }
  172.  
  173.  
  174. /*
  175. * 添加订单+展示预约时间
  176. * @param openId
  177. * @param storeId
  178. */
  179. public String outwardManageOrder() throws Exception{
  180. ActionContext ctx = ActionContext.getContext();
  181. String openId = (String) ctx.get("openId");
  182. User user = userService.getUser(openId);
  183. System.out.println(storeId);
  184. Store store = storeService.getStore(storeId);
  185. Set<Services> listser = store.getServices();
  186. ArrayList<String> stt = this.showTimetable(store);
  187.  
  188. resultMap = new HashMap<String, Object>();
  189. resultMap.put("timetable", stt);
  190.  
  191. JSONObject json = JSONObject.fromObject(resultMap);
  192. ctx.put("data", json);
  193. ctx.put("user", user);
  194. ctx.put("store", store);
  195. ctx.put("listser", listser);
  196. return "outwardManageOrder";
  197. }
  198.  
  199. /*
  200. * 处理申请
  201. * @param pass 1/0
  202. * @servicesId
  203. */
  204. // public String dealServicess() throws Exception{
  205. // Services services = servicesService.getServices(servicesId);
  206. // resultMap = new HashMap<String, Object>();
  207. //
  208. // if(pass == 1){
  209. // services.setPass(1);
  210. // services.getUser().setStore(services.getStore());
  211. // } else if(pass == 0){
  212. // services.setPass(0);
  213. // }
  214. // services.setStatus(1);
  215. // servicesService.updateServices(services);
  216. // resultMap.put("status", true);
  217. // resultMap.put("ret", pass==1?"已通过申请":"已拒绝申请");
  218. // return SUCCESS;
  219. // }
  220.  
  221.  
  222. /*
  223. * 店主跳转到商店信息页面
  224. * @param openId
  225. */
  226. public String outwardStoreManage() throws Exception{
  227. ActionContext ctx = ActionContext.getContext();
  228. String openId = (String) ctx.get("openId");
  229. Store store = userService.getUser(openId).getStore();
  230. Set<Timetable> timelist = store.getTimetables();
  231. System.out.println(timelist.size());
  232. ctx.put("store", store);
  233. ctx.put("timelist", timelist);
  234.  
  235. return "outwardStoreManage";
  236. }
  237.  
  238. /*
  239. * 修改商店名称
  240. * @param openId
  241. */
  242. public String updateStoreName() throws Exception{
  243. ActionContext ctx = ActionContext.getContext();
  244. resultMap = new HashMap<String, Object>();
  245. String openId = (String) ctx.get("openId");
  246.  
  247. Store store = userService.getUser(openId).getStore();
  248. store.setStorename(storename);
  249. store.setAddress(address);
  250. storeService.updateStore(store);
  251.  
  252. resultMap.put("status", true);
  253. resultMap.put("ret", "修改成功");
  254. return SUCCESS;
  255. }
  256.  
  257.  
  258. /*
  259. * 整合工作时间
  260. * @Timetable tt
  261. * @return ArrayList<String> stt
  262. */
  263. public ArrayList<String> showTimetable(Store store){
  264. List<Timetable> tts = new ArrayList<Timetable>(store.getTimetables());
  265. ArrayList<String> stt = new ArrayList<String>();
  266. for (int b=0;b<7;b++){
  267. stt.add(b, "");
  268. }
  269. for(int i = 0;i<tts.size();i++){
  270. if(tts.get(i).getIsOn()==true){
  271. Timetable ti = tts.get(i);
  272. System.out.printf("i="+i+";");
  273. for(int j = 0;j<ti.getWeekday().length();j=j+2){
  274. System.out.print("j="+j+";");
  275. Integer wd = Integer.valueOf(ti.getWeekday().charAt(j)+"");
  276. System.out.println("wd="+wd);
  277. Integer st = Integer.valueOf(ti.getStarttime().substring(0, 2));
  278. System.out.printf("st="+st+";");
  279. Integer ed = Integer.valueOf(ti.getEndtime().substring(0, 2));
  280. System.out.println("ed="+ed+";");
  281. String ts = "";
  282. int dd = ed-st;
  283. for(int k = 0;k<dd;k++ ){
  284. int s = st+k;
  285. System.out.printf("s="+s+";");
  286. System.out.println("tsb="+ts+";");
  287. ts= ts+s+",";
  288. System.out.println("ts="+ts+";");
  289. }
  290. stt.set(wd,ts);
  291. System.out.println("stt[wd]="+stt.get(wd));
  292. }
  293. }
  294. }
  295. for(int a = 0;a<stt.size();a++){
  296. System.out.println(a+" : "+stt.get(a));
  297. }
  298. System.out.println(stt);
  299. return stt;
  300. }
  301.  
  302. public IStoreService getStoreService() {
  303. return storeService;
  304. }
  305.  
  306. public void setStoreService(IStoreService storeService) {
  307. this.storeService = storeService;
  308. }
  309.  
  310. public IUserService getUserService() {
  311. return userService;
  312. }
  313.  
  314. public void setUserService(IUserService userService) {
  315. this.userService = userService;
  316. }
  317.  
  318. public IServicesService getServicesService() {
  319. return servicesService;
  320. }
  321.  
  322. public void setServicesService(IServicesService servicesService) {
  323. this.servicesService = servicesService;
  324. }
  325.  
  326. public Integer getStoreId() {
  327. return storeId;
  328. }
  329.  
  330. public void setStoreId(Integer storeId) {
  331. this.storeId = storeId;
  332. }
  333.  
  334. public String getStorename() {
  335. return storename;
  336. }
  337.  
  338. public void setStorename(String storename) {
  339. this.storename = storename;
  340. }
  341.  
  342. public String getAddress() {
  343. return address;
  344. }
  345.  
  346. public void setAddress(String address) {
  347. this.address = address;
  348. }
  349.  
  350. public String getUserId() {
  351. return userId;
  352. }
  353.  
  354. public void setUserId(String userId) {
  355. this.userId = userId;
  356. }
  357.  
  358. public String getOpenId() {
  359. return openId;
  360. }
  361.  
  362. public void setOpenId(String openId) {
  363. this.openId = openId;
  364. }
  365.  
  366. public HashMap<String, Object> getResultMap() {
  367. return resultMap;
  368. }
  369.  
  370. public void setResultMap(HashMap<String, Object> resultMap) {
  371. this.resultMap = resultMap;
  372. }
  373.  
  374. public IAnnounceService getAnnounceService() {
  375. return announceService;
  376. }
  377.  
  378. public void setAnnounceService(IAnnounceService announceService) {
  379. this.announceService = announceService;
  380. }
  381.  
  382. public ITimetableService getTimetableService() {
  383. return timetableService;
  384. }
  385.  
  386. public void setTimetableService(ITimetableService timetableService) {
  387. this.timetableService = timetableService;
  388. }
  389.  
  390. public Integer getAnnounceId() {
  391. return announceId;
  392. }
  393.  
  394. public void setAnnounceId(Integer announceId) {
  395. this.announceId = announceId;
  396. }
  397.  
  398. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement