adminManagerAction.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. package com.happy.action;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.google.gson.Gson;
  4. import com.google.gson.reflect.TypeToken;
  5. import com.happy.Model.*;
  6. import com.happy.Model.AdminManager;
  7. import com.happy.Until.GetHttpParam;
  8. import com.happy.Until.PwdDefind;
  9. import com.happy.Until.ResUtil;
  10. import com.happy.Until.UUIDUtil;
  11. import com.happy.dto.IPage;
  12. import com.happy.service.*;
  13. import com.opensymphony.xwork2.ActionSupport;
  14. import net.sf.json.JSONObject;
  15. import org.apache.struts2.ServletActionContext;
  16. import org.apache.struts2.interceptor.ServletRequestAware;
  17. import javax.annotation.Resource;
  18. import javax.servlet.http.HttpServletRequest;
  19. import javax.servlet.http.HttpServletResponse;
  20. import java.io.File;
  21. import java.util.List;
  22. public class adminManagerAction extends ActionSupport implements ServletRequestAware{
  23. private HttpServletRequest request;
  24. public HttpServletResponse response;
  25. @Resource
  26. public AdminService adminService;
  27. @Resource
  28. public AdminManagerService adminManagerService;
  29. @Resource
  30. public HotelService hotelService;
  31. @Resource
  32. public BookService bookService;
  33. @Resource
  34. public FileService fileService;
  35. public String adminName;
  36. public String password;
  37. public String hotelTownship;
  38. public Integer managerId;//商户Id
  39. public Integer id;
  40. public String level;//权限
  41. public int page; // 当前页
  42. public int rows;// 每页显示的行数rows
  43. public String fileListJson;
  44. public HttpServletRequest getRequest() {
  45. return request;
  46. }
  47. public void setRequest(HttpServletRequest request) {
  48. this.request = request;
  49. }
  50. public void setServletRequest(HttpServletRequest request) {
  51. this.request = request;
  52. }
  53. public HttpServletResponse getResponse() {
  54. return response;
  55. }
  56. public void setResponse(HttpServletResponse response) {
  57. this.response = response;
  58. }
  59. /**
  60. * 描述:登录
  61. * @return
  62. */
  63. public String loginAdmin() {
  64. JSONObject resultJson = new JSONObject();
  65. StringBuilder getOneSqlx = new StringBuilder("");
  66. getOneSqlx.append(" and admin_name = '").append(adminName).append("'");
  67. AdminManager login = adminManagerService.getOen(getOneSqlx.toString());
  68. StringBuilder getOneSqlx1 = new StringBuilder("");
  69. getOneSqlx1.append(" and admin_name = '").append(adminName).append("'")
  70. .append(" and password = '").append(password).append("'");
  71. AdminManager login1 = adminManagerService.getOen(getOneSqlx1.toString());
  72. if (login != null) {
  73. if(login1 == null){
  74. resultJson.put("message", "用户名或密码错误");
  75. resultJson.put("code", 205);
  76. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  77. return null;
  78. }
  79. if(login.getStatus()==2){
  80. resultJson.put("message", "账号已冻结请联系管理员");
  81. resultJson.put("code", 205);
  82. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  83. return null;
  84. }else{
  85. //是否主账号首次登录
  86. Hotel hotel = hotelService.getOen("and manager_id = "+login.getManagerId()+"");
  87. if(hotel==null && "2".equals(login.getLevel())){
  88. resultJson.put("isLogin",1);
  89. }else{
  90. resultJson.put("isLogin",0);
  91. }
  92. login.setPassword("********");
  93. resultJson.put("message", "登录成功");
  94. resultJson.put("code", 200);
  95. resultJson.put("data", login);
  96. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  97. return null;
  98. }
  99. }
  100. resultJson.put("message", "该账户不存在");
  101. resultJson.put("code", 205);
  102. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  103. return null;
  104. }
  105. /**
  106. * 描述:新增管理端民宿账号
  107. * @return
  108. */
  109. public String insertAdmin() {
  110. JSONObject resultJson = new JSONObject();
  111. Gson gson = new Gson();
  112. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  113. if (json == null) {
  114. resultJson.put("message", "请传入参数");
  115. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  116. return null;
  117. }
  118. AdminManager admin = null;
  119. try {
  120. admin = gson.fromJson(json.toString(), new TypeToken<AdminManager>() {}.getType());
  121. if (admin == null) {
  122. resultJson.put("message", "数据为空");
  123. resultJson.put("code", 500);
  124. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  125. return null;
  126. }
  127. if (admin.getAdminName()==null || admin.getHotelName()==null || admin.getHotelTownship()==null || "".equals(admin.getHotelTownship())
  128. || admin.getLevel()==null || admin.getCardName()==null || admin.getCorpnPhone()==null){
  129. resultJson.put("message", "各参数不能为空");
  130. resultJson.put("code", 500);
  131. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  132. return null;
  133. }
  134. if (!PwdDefind.vertify(admin.getPassword())){
  135. resultJson.put("message", "密码至少包含:大小写英文字母、数字、特殊符号,密码长度大于8位,小于20位");
  136. resultJson.put("code", 500);
  137. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  138. return null;
  139. }
  140. StringBuilder getOneSqlx = new StringBuilder("");
  141. getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'");
  142. AdminManager listc = adminManagerService.getOen(getOneSqlx.toString());
  143. if (listc != null) {
  144. resultJson.put("message", "该用户已存在");
  145. resultJson.put("code", 500);
  146. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  147. return null;
  148. }
  149. admin.setId(Math.toIntExact(UUIDUtil.generateID()));
  150. admin.setManagerId(admin.getId());
  151. //保存详细图附件
  152. List<FileInfo> fileInfoList = JSONArray.parseArray(fileListJson, FileInfo.class);
  153. if(fileInfoList!=null && fileInfoList.size()>0){
  154. for(FileInfo file : fileInfoList){
  155. FileInfo fileInfo = fileService.getById(file.getId());
  156. file.setLinkId(admin.getId());
  157. if(fileInfo==null){
  158. fileService.insertFile(file);
  159. }else{
  160. fileService.updateFile(file);
  161. }
  162. }
  163. }
  164. int m = adminManagerService.insertAdmin(admin);
  165. if (m > 0) {
  166. resultJson.put("message", "添加成功");
  167. resultJson.put("code", 200);
  168. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  169. return null;
  170. } else {
  171. resultJson.put("message", "添加失败");
  172. resultJson.put("code", 502);
  173. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  174. return null;
  175. }
  176. } catch (Exception e) {
  177. e.printStackTrace();
  178. }
  179. resultJson.put("message", "未知异常");
  180. resultJson.put("code", 205);
  181. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  182. return null;
  183. }
  184. /**
  185. * 描述:修改管理端民宿账号
  186. * @return
  187. */
  188. public String updateAdmin() {
  189. JSONObject resultJson = new JSONObject();
  190. Gson gson = new Gson();
  191. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  192. if (json == null) {
  193. resultJson.put("message", "请传入参数");
  194. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  195. return null;
  196. }
  197. AdminManager admin = null;
  198. try {
  199. admin = gson.fromJson(json.toString(), new TypeToken<AdminManager>() {}.getType());
  200. if (admin == null) {
  201. resultJson.put("message", "数据为空");
  202. resultJson.put("code", 500);
  203. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  204. return null;
  205. }
  206. if(admin.getId()==null){
  207. resultJson.put("message", "修改用户Id不能为空");
  208. resultJson.put("code", 500);
  209. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  210. return null;
  211. }
  212. if (admin.getAdminName()==null || admin.getCorpnName()==null || admin.getHotelTownship()==null || "".equals(admin.getHotelTownship())
  213. || admin.getLevel()==null || admin.getCardName()==null || admin.getCorpnPhone()==null){
  214. resultJson.put("message", "各参数不能为空");
  215. resultJson.put("code", 500);
  216. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  217. return null;
  218. }
  219. if(admin.getPassword()!=null && !"".equals(admin.getPassword())){
  220. if (!PwdDefind.vertify(admin.getPassword())){
  221. resultJson.put("message", "密码至少包含:大小写英文字母、数字、特殊符号,密码长度大于8位,小于20位");
  222. resultJson.put("code", 500);
  223. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  224. return null;
  225. }
  226. }
  227. StringBuilder getOneSqlx = new StringBuilder("");
  228. getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'");
  229. getOneSqlx.append(" and id != '").append(admin.getId()).append("'");
  230. AdminManager listc = adminManagerService.getOen(getOneSqlx.toString());
  231. if (listc != null) {
  232. resultJson.put("message", "该用户已存在");
  233. resultJson.put("code", 500);
  234. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  235. return null;
  236. }
  237. //修改详细图附件
  238. List<FileInfo> fileInfoList = JSONArray.parseArray(fileListJson, FileInfo.class);
  239. if(fileInfoList!=null && fileInfoList.size()>0){
  240. if(admin.getId()!= null){
  241. fileService.delLinkFile(admin.getId());
  242. }
  243. for(FileInfo file : fileInfoList){
  244. FileInfo fileInfo = fileService.getById(file.getId());
  245. file.setLinkId(admin.getId());
  246. if(fileInfo==null){
  247. fileService.insertFile(file);
  248. }else{
  249. fileService.updateFile(file);
  250. }
  251. }
  252. }
  253. int m = adminManagerService.updateAdmin(admin);
  254. if (m > 0) {
  255. resultJson.put("message", "修改成功");
  256. resultJson.put("code", 200);
  257. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  258. return null;
  259. } else {
  260. resultJson.put("message", "修改失败");
  261. resultJson.put("code", 502);
  262. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  263. return null;
  264. }
  265. } catch (Exception e) {
  266. e.printStackTrace();
  267. }
  268. resultJson.put("message", "未知异常");
  269. resultJson.put("code", 205);
  270. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  271. return null;
  272. }
  273. /**
  274. * 描述:新增民宿端普通账号
  275. * @return
  276. */
  277. public String insertAdminManager() {
  278. JSONObject resultJson = new JSONObject();
  279. Gson gson = new Gson();
  280. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  281. if (json == null) {
  282. resultJson.put("message", "请传入参数");
  283. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  284. return null;
  285. }
  286. AdminManager admin = null;
  287. try {
  288. admin = gson.fromJson(json.toString(), new TypeToken<AdminManager>() {}.getType());
  289. if (admin == null) {
  290. resultJson.put("message", "数据为空");
  291. resultJson.put("code", 500);
  292. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  293. return null;
  294. }
  295. if (admin.getAdminName()==null || admin.getCorpnName()==null || admin.getCorpnPhone()==null
  296. || admin.getLevel()==null || admin.getPassword()==null){
  297. resultJson.put("message", "各参数不能为空");
  298. resultJson.put("code", 500);
  299. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  300. return null;
  301. }
  302. if(admin.getManagerId()==null){
  303. resultJson.put("message", "民宿超级管理员Id不能为空");
  304. resultJson.put("code", 500);
  305. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  306. return null;
  307. }
  308. if (!PwdDefind.vertify(admin.getPassword())){
  309. resultJson.put("message", "密码至少包含:大小写英文字母、数字、特殊符号,密码长度大于8位,小于20位");
  310. resultJson.put("code", 500);
  311. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  312. return null;
  313. }
  314. StringBuilder getOneSqlx = new StringBuilder("");
  315. getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'");
  316. AdminManager listc = adminManagerService.getOen(getOneSqlx.toString());
  317. if (listc != null) {
  318. resultJson.put("message", "该用户已存在");
  319. resultJson.put("code", 500);
  320. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  321. return null;
  322. }
  323. int m = adminManagerService.insertAdmin(admin);
  324. if (m > 0) {
  325. resultJson.put("message", "添加成功");
  326. resultJson.put("code", 200);
  327. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  328. return null;
  329. } else {
  330. resultJson.put("message", "添加失败");
  331. resultJson.put("code", 502);
  332. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  333. return null;
  334. }
  335. } catch (Exception e) {
  336. e.printStackTrace();
  337. }
  338. resultJson.put("message", "未知异常");
  339. resultJson.put("code", 205);
  340. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  341. return null;
  342. }
  343. /**
  344. * 描述:修改民宿端普通账号
  345. * @return
  346. */
  347. public String updateAdminManager() {
  348. JSONObject resultJson = new JSONObject();
  349. Gson gson = new Gson();
  350. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  351. if (json == null) {
  352. resultJson.put("message", "请传入参数");
  353. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  354. return null;
  355. }
  356. AdminManager admin = null;
  357. try {
  358. admin = gson.fromJson(json.toString(), new TypeToken<AdminManager>() {}.getType());
  359. if (admin == null) {
  360. resultJson.put("message", "数据为空");
  361. resultJson.put("code", 500);
  362. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  363. return null;
  364. }
  365. if (admin.getId()==null){
  366. resultJson.put("message", "用户主键不能为空");
  367. resultJson.put("code", 500);
  368. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  369. return null;
  370. }
  371. if (admin.getPassword()!=null && !"".equals(admin.getPassword()) && !PwdDefind.vertify(admin.getPassword())){
  372. resultJson.put("message", "密码至少包含:大小写英文字母、数字、特殊符号,密码长度大于8位,小于20位");
  373. resultJson.put("code", 500);
  374. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  375. return null;
  376. }
  377. StringBuilder getOneSqlx = new StringBuilder("");
  378. getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'");
  379. getOneSqlx.append(" and id != '").append(admin.getId()).append("'");
  380. AdminManager listc = adminManagerService.getOen(getOneSqlx.toString());
  381. if (listc != null) {
  382. resultJson.put("message", "该用户已存在");
  383. resultJson.put("code", 500);
  384. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  385. return null;
  386. }
  387. int m = adminManagerService.updateAdmin(admin);
  388. if (m > 0) {
  389. resultJson.put("message", "修改成功");
  390. resultJson.put("code", 200);
  391. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  392. return null;
  393. } else {
  394. resultJson.put("message", "修改失败");
  395. resultJson.put("code", 502);
  396. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  397. return null;
  398. }
  399. } catch (Exception e) {
  400. e.printStackTrace();
  401. }
  402. resultJson.put("message", "未知异常");
  403. resultJson.put("code", 205);
  404. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  405. return null;
  406. }
  407. /**
  408. * 描述:删除
  409. * @return
  410. */
  411. public String delAdmin(){
  412. JSONObject resultJson = new JSONObject();
  413. if (id == null) {
  414. resultJson.put("message", "请传入id");
  415. resultJson.put("code", 500);
  416. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  417. return null;
  418. }
  419. AdminManager admin = adminManagerService.getById(id);
  420. StringBuilder booksql = new StringBuilder("");
  421. booksql.append(" and hotel_manager_id = '").append(admin.getManagerId()).append("'");
  422. booksql.append(" and order_status in (1,2,3,4,10) ");
  423. List<Booking> bookingList = bookService.queryList(booksql.toString());
  424. if(bookingList!=null && bookingList.size()>0){
  425. resultJson.put("message", "该民宿存在未完成的订单,禁止删除");
  426. resultJson.put("code", 500);
  427. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  428. return null;
  429. }
  430. int m = adminManagerService.delAdmin(id);
  431. if (m > 0) {
  432. //冻结旗下所有民宿、账号
  433. if(admin.getManagerId()!=null){
  434. //民宿
  435. Hotel hotel = hotelService.getByManagerId(admin.getManagerId());
  436. if(hotel!=null){
  437. hotel.setStatus(0);
  438. hotelService.updateHotel(hotel);
  439. }
  440. //员工账号
  441. StringBuilder managersql = new StringBuilder("");
  442. managersql.append(" and manager_id = '").append(admin.getManagerId()).append("'");
  443. managersql.append(" and level = 1 ");
  444. List<AdminManager> managerList = adminManagerService.queryList(managersql.toString());
  445. if(managerList!=null){
  446. for(AdminManager manager : managerList){
  447. manager.setStatus(0);
  448. adminManagerService.updateAdmin(manager);
  449. }
  450. }
  451. }
  452. resultJson.put("message", "删除成功");
  453. resultJson.put("code", 200);
  454. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  455. return null;
  456. }
  457. resultJson.put("message", "未知异常");
  458. resultJson.put("code", 205);
  459. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  460. return null;
  461. }
  462. /**
  463. * 描述:重置密码
  464. * @return
  465. */
  466. public String removePwd(){
  467. JSONObject resultJson = new JSONObject();
  468. if (id == null) {
  469. resultJson.put("message", "请传入id");
  470. resultJson.put("code", 500);
  471. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  472. return null;
  473. }
  474. AdminManager admin = adminManagerService.getById(id);
  475. if (admin != null && !"".equals(admin)) {
  476. admin.setPassword("Jams_123456");
  477. int m = adminManagerService.updateAdmin(admin);
  478. if(m > 0){
  479. resultJson.put("message", "重置成功");
  480. resultJson.put("code", 200);
  481. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  482. return null;
  483. }else{
  484. resultJson.put("message", "重置失败");
  485. resultJson.put("code", 502);
  486. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  487. return null;
  488. }
  489. }
  490. resultJson.put("message", "未知异常");
  491. resultJson.put("code", 205);
  492. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  493. return null;
  494. }
  495. /**
  496. * 描述:冻结账号
  497. * @return
  498. */
  499. public String freezeAdmin(){
  500. JSONObject resultJson = new JSONObject();
  501. if (id == null) {
  502. resultJson.put("message", "请传入id");
  503. resultJson.put("code", 500);
  504. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  505. return null;
  506. }
  507. AdminManager admin = adminManagerService.getById(id);
  508. if (admin != null && !"".equals(admin)) {
  509. //冻结旗下所有民宿、账号
  510. if(admin.getManagerId()!=null){
  511. //民宿
  512. Hotel hotel = hotelService.getByManagerId(admin.getManagerId());
  513. if(hotel!=null){
  514. hotel.setStatus(2);
  515. hotelService.updateHotel(hotel);
  516. }
  517. //员工账号
  518. StringBuilder managersql = new StringBuilder("");
  519. managersql.append(" and manager_id = '").append(admin.getManagerId()).append("'");
  520. managersql.append(" and level = 1 ");
  521. List<AdminManager> managerList = adminManagerService.queryList(managersql.toString());
  522. if(managerList!=null){
  523. for(AdminManager manager : managerList){
  524. manager.setStatus(2);
  525. adminManagerService.updateAdmin(manager);
  526. }
  527. }
  528. }
  529. admin.setStatus(2);
  530. int m = adminManagerService.updateAdmin(admin);
  531. if(m > 0){
  532. resultJson.put("message", "冻结成功");
  533. resultJson.put("code", 200);
  534. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  535. return null;
  536. }else{
  537. resultJson.put("message", "冻结失败");
  538. resultJson.put("code", 502);
  539. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  540. return null;
  541. }
  542. }
  543. resultJson.put("message", "未知异常");
  544. resultJson.put("code", 205);
  545. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  546. return null;
  547. }
  548. /**
  549. * 描述:解冻账号
  550. * @return
  551. */
  552. public String thawAdmin(){
  553. JSONObject resultJson = new JSONObject();
  554. if (id == null) {
  555. resultJson.put("message", "请传入id");
  556. resultJson.put("code", 500);
  557. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  558. return null;
  559. }
  560. AdminManager admin = adminManagerService.getById(id);
  561. if (admin != null && !"".equals(admin)) {
  562. //冻结旗下所有民宿、账号
  563. if(admin.getManagerId()!=null){
  564. //民宿
  565. Hotel hotel = hotelService.getByManagerId(admin.getManagerId());
  566. if(hotel!=null){
  567. hotel.setStatus(1);
  568. hotelService.updateHotel(hotel);
  569. }
  570. //员工账号
  571. StringBuilder managersql = new StringBuilder("");
  572. managersql.append(" and manager_id = '").append(admin.getManagerId()).append("'");
  573. managersql.append(" and level = 1 ");
  574. List<AdminManager> managerList = adminManagerService.queryList(managersql.toString());
  575. if(managerList!=null){
  576. for(AdminManager manager : managerList){
  577. manager.setStatus(1);
  578. adminManagerService.updateAdmin(manager);
  579. }
  580. }
  581. }
  582. admin.setStatus(1);
  583. int m = adminManagerService.updateAdmin(admin);
  584. if(m > 0){
  585. resultJson.put("message", "解冻成功");
  586. resultJson.put("code", 200);
  587. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  588. return null;
  589. }else{
  590. resultJson.put("message", "解冻成功");
  591. resultJson.put("code", 502);
  592. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  593. return null;
  594. }
  595. }
  596. resultJson.put("message", "未知异常");
  597. resultJson.put("code", 205);
  598. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  599. return null;
  600. }
  601. /**
  602. * 描述:分页查询
  603. * @return
  604. */
  605. public String queryPage(){
  606. JSONObject resultJson = new JSONObject();
  607. StringBuilder s1 = new StringBuilder("");
  608. if (adminName!=null){
  609. s1.append(" and ( admin_name like '%").append(adminName).append("%'")
  610. .append(" or hotel_name like '%").append(adminName).append("%'")
  611. .append(" or corpn_name like '%").append(adminName).append("%'")
  612. .append(" or corpn_phone like '%").append(adminName).append("%')");
  613. }
  614. if (hotelTownship!=null){
  615. s1.append(" and hotel_township = '").append(hotelTownship).append("'");
  616. }
  617. if(managerId!=null){
  618. s1.append(" and manager_id = ").append(managerId);
  619. }
  620. if(level!=null){
  621. s1.append(" and level = '").append(level).append("'");
  622. }
  623. IPage<AdminManager> adminIPage = adminManagerService.queryPage(s1.toString(),page,rows);
  624. if(adminIPage!=null && !"".equals(adminIPage)){
  625. resultJson.put("message", "查询分页成功");
  626. resultJson.put("code", 200);
  627. resultJson.put("data", adminIPage);
  628. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  629. }else{
  630. resultJson.put("message", "查询分页失败");
  631. resultJson.put("code", 500);
  632. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  633. }
  634. return null;
  635. }
  636. /**
  637. * 描述:根据Id查询详细
  638. * @return
  639. */
  640. public String getById(){
  641. JSONObject resultJson = new JSONObject();
  642. if (id == null) {
  643. resultJson.put("message", "请传入id");
  644. resultJson.put("code", 500);
  645. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  646. return null;
  647. }
  648. AdminManager admin = adminManagerService.getById(id);
  649. List<FileInfo> fileInfoList = fileService.queryList("and link_id ='"+id+"'");
  650. admin.setFileInfoList(fileInfoList);
  651. if (admin != null) {
  652. resultJson.put("message", "查询成功");
  653. resultJson.put("code", 200);
  654. resultJson.put("data", admin);
  655. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  656. return null;
  657. }else{
  658. resultJson.put("message", "未查到用户信息");
  659. resultJson.put("code", 500);
  660. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  661. return null;
  662. }
  663. }
  664. /**
  665. * 描述:查询菜单
  666. * @return
  667. */
  668. public String getIndexList(){
  669. JSONObject resultjson = new JSONObject();
  670. StringBuilder s1 = new StringBuilder("");
  671. if (id==null){
  672. resultjson.put("message", "请传入用户Id");
  673. resultjson.put("code", 500);
  674. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  675. return null;
  676. }
  677. AdminManager admin = adminManagerService.getById(id);
  678. if (admin==null){
  679. resultjson.put("message", "未查到用户信息");
  680. resultjson.put("code", 500);
  681. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  682. return null;
  683. }
  684. String ids = admin.getAdminPower();
  685. s1.append(" and id in (").append(ids).append(") ");
  686. List<AdminPower> lpower = adminService.queryTree(s1.toString());
  687. if (lpower!=null){
  688. resultjson.put("message", "返回成功");
  689. resultjson.put("code", 200);
  690. resultjson.put("data",lpower);
  691. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  692. return null;
  693. }
  694. resultjson.put("message", "数据为空");
  695. resultjson.put("code", 205);
  696. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  697. return null;
  698. }
  699. }