NBUserManageController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. using LeaRun.Application.Busines.NBManage;
  2. using LeaRun.Util.WebControl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using LeaRun.Util;
  9. using Newtonsoft.Json.Linq;
  10. namespace LeaRun.Application.Web.Areas.NBManage.Controllers
  11. {
  12. public class NBUserManageController : MvcControllerBase
  13. {
  14. // GET: /NBManage/NBUserManage/
  15. NBUserManageBLL bll = new NBUserManageBLL();
  16. #region 用户管理
  17. public ActionResult Index()
  18. {
  19. return View();
  20. }
  21. /// <summary>
  22. /// 小区form
  23. /// </summary>
  24. /// <returns></returns>
  25. public ActionResult AreaForm()
  26. {
  27. return View();
  28. }
  29. /// <summary>
  30. /// 楼宇form
  31. /// </summary>
  32. /// <returns></returns>
  33. public ActionResult BldgForm()
  34. {
  35. return View();
  36. }
  37. /// <summary>
  38. /// 单元form
  39. /// </summary>
  40. /// <returns></returns>
  41. public ActionResult ApmtForm()
  42. {
  43. return View();
  44. }
  45. /// <summary>
  46. /// 用户form
  47. /// </summary>
  48. /// <returns></returns>
  49. public ActionResult UserForm()
  50. {
  51. return View();
  52. }
  53. /// <summary>
  54. /// 表具 from
  55. /// </summary>
  56. /// <returns></returns>
  57. public ActionResult MeterForm()
  58. {
  59. return View();
  60. }
  61. #endregion
  62. #region 获取用户管理数据列表
  63. /// <summary>
  64. /// 获取用户管理数据列表
  65. /// </summary>
  66. /// <param name="pagination"></param>
  67. /// <param name="keyword"></param>
  68. /// <param name="searchType"></param>
  69. /// <param name="id"></param>
  70. /// <returns></returns>
  71. [HttpGet]
  72. public ActionResult GetNBUserList(Pagination pagination, string keyword, string searchType, string id, string level)
  73. {
  74. return Content(bll.GetNBUserList(pagination, keyword, searchType, id, level));
  75. }
  76. #endregion
  77. #region 保存区域数据
  78. /// <summary>
  79. /// 保存区域数据
  80. /// </summary>
  81. /// <param name="keyValue"></param>
  82. /// <param name="data"></param>
  83. /// <returns></returns>
  84. [HttpPost]
  85. [ValidateAntiForgeryToken]
  86. [AjaxOnly]
  87. public ActionResult SaveAreaForm(string keyValue, string data)
  88. {
  89. if (string.IsNullOrEmpty(keyValue))
  90. {
  91. switch (bll.SaveAreaForm(data))
  92. {
  93. case 0:
  94. return Error("保存失败。");
  95. case 1:
  96. return Success("保存成功。");
  97. case 2:
  98. return Error("重复数据。");
  99. default:
  100. return Error("保存失败。");
  101. }
  102. }
  103. else
  104. {
  105. switch (bll.EditAreaForm(keyValue, data))
  106. {
  107. case 0:
  108. return Error("修改失败。");
  109. case 1:
  110. return Success("修改成功。");
  111. case 2:
  112. return Error("重复数据。");
  113. default:
  114. return Error("修改失败。");
  115. }
  116. }
  117. }
  118. #endregion
  119. #region 获取小区信息
  120. /// <summary>
  121. /// 获取小区信息
  122. /// </summary>
  123. /// <param name="id"></param>
  124. /// <returns></returns>
  125. public ActionResult GetAreaInfo(string id)
  126. {
  127. return Content(bll.GetAreaInfo(id));
  128. }
  129. #endregion
  130. #region 删除小区信息
  131. /// <summary>
  132. /// 删除小区信息
  133. /// </summary>
  134. /// <param name="id"></param>
  135. /// <returns></returns>
  136. public ActionResult DeleteAreaForm(string id)
  137. {
  138. switch (bll.DeleteAreaForm(id))
  139. {
  140. case 2:
  141. return Error("有下级数据,不允许删除。");
  142. case 1:
  143. return Success("删除成功。");
  144. case 0:
  145. return Error("删除失败。");
  146. default:
  147. return Error("删除失败。");
  148. }
  149. }
  150. #endregion
  151. #region 保存楼宇数据
  152. /// <summary>
  153. /// 保存楼宇数据
  154. /// </summary>
  155. /// <param name="keyValue"></param>
  156. /// <param name="data"></param>
  157. /// <returns></returns>
  158. [HttpPost]
  159. [ValidateAntiForgeryToken]
  160. [AjaxOnly]
  161. public ActionResult SaveBldgForm(string keyValue, string parentId, string data)
  162. {
  163. if (string.IsNullOrEmpty(keyValue))
  164. {
  165. switch (bll.SaveBldgForm(parentId, data))
  166. {
  167. case 0:
  168. return Error("保存失败。");
  169. case 1:
  170. return Success("保存成功。");
  171. case 2:
  172. return Error("重复数据。");
  173. default:
  174. return Error("保存失败。");
  175. }
  176. }
  177. else
  178. {
  179. switch (bll.EditBldgForm(parentId, keyValue, data))
  180. {
  181. case 0:
  182. return Error("修改失败。");
  183. case 1:
  184. return Success("修改成功。");
  185. case 2:
  186. return Error("重复数据。");
  187. default:
  188. return Error("修改失败。");
  189. }
  190. }
  191. }
  192. /// <summary>
  193. /// 保存楼宇数据
  194. /// </summary>
  195. /// <param name="keyValue"></param>
  196. /// <param name="data"></param>
  197. /// <returns></returns>
  198. [HttpPost]
  199. [ValidateAntiForgeryToken]
  200. [AjaxOnly]
  201. public ActionResult SaveBatchBldgForm(string parentId, string data)
  202. {
  203. bll.SaveBatchBldgForm(parentId, data);
  204. return Success("修改成功。");
  205. }
  206. #endregion
  207. #region 获取楼宇信息
  208. /// <summary>
  209. /// 获取楼宇信息
  210. /// </summary>
  211. /// <param name="id"></param>
  212. /// <returns></returns>
  213. public ActionResult GetBldgInfo(string id)
  214. {
  215. return Content(bll.GetBldgInfo(id));
  216. }
  217. #endregion
  218. #region 删除楼宇信息
  219. /// <summary>
  220. /// 删除小区信息
  221. /// </summary>
  222. /// <param name="id"></param>
  223. /// <returns></returns>
  224. public ActionResult DeleteBldgForm(string id)
  225. {
  226. switch (bll.DeleteBldgForm(id))
  227. {
  228. case 2:
  229. return Error("有下级数据,不允许删除。");
  230. case 1:
  231. return Success("删除成功。");
  232. case 0:
  233. return Error("删除失败。");
  234. default:
  235. return Error("删除失败。");
  236. }
  237. }
  238. #endregion
  239. #region 保存单元数据
  240. /// <summary>
  241. /// 保存单元数据
  242. /// </summary>
  243. /// <param name="keyValue"></param>
  244. /// <param name="data"></param>
  245. /// <returns></returns>
  246. [HttpPost]
  247. [ValidateAntiForgeryToken]
  248. [AjaxOnly]
  249. public ActionResult SaveApmtForm(string keyValue, string parentId, string data)
  250. {
  251. if (string.IsNullOrEmpty(keyValue))
  252. {
  253. switch (bll.SaveApmtForm(parentId, data))
  254. {
  255. case 0:
  256. return Error("保存失败。");
  257. case 1:
  258. return Success("保存成功。");
  259. case 2:
  260. return Error("重复数据。");
  261. default:
  262. return Error("保存失败。");
  263. }
  264. }
  265. else
  266. {
  267. switch (bll.EditApmtForm(parentId, keyValue, data))
  268. {
  269. case 0:
  270. return Error("修改失败。");
  271. case 1:
  272. return Success("修改成功。");
  273. case 2:
  274. return Error("重复数据。");
  275. default:
  276. return Error("修改失败。");
  277. }
  278. }
  279. }
  280. /// <summary>
  281. /// 批量保存单元数据
  282. /// </summary>
  283. /// <param name="data"></param>
  284. /// <returns></returns>
  285. [HttpPost]
  286. [ValidateAntiForgeryToken]
  287. [AjaxOnly]
  288. public ActionResult SaveBatchApmtForm(string parentId, string data)
  289. {
  290. bll.SaveBatchApmtForm(parentId, data);
  291. return Success("修改成功。");
  292. }
  293. #endregion
  294. #region 获取单元信息
  295. /// <summary>
  296. /// 获取单元信息
  297. /// </summary>
  298. /// <param name="id"></param>
  299. /// <returns></returns>
  300. public ActionResult GetApmtInfo(string id)
  301. {
  302. return Content(bll.GetApmtInfo(id));
  303. }
  304. #endregion
  305. #region 删除单元信息
  306. /// <summary>
  307. /// 删除单元信息
  308. /// </summary>
  309. /// <param name="id"></param>
  310. /// <returns></returns>
  311. public ActionResult DeleteApmtForm(string id)
  312. {
  313. switch (bll.DeleteApmtForm(id))
  314. {
  315. case 1:
  316. return Success("删除成功。");
  317. case 0:
  318. return Error("删除失败。");
  319. case 2:
  320. return Error("有下级数据,不允许删除。");
  321. default:
  322. return Error("删除失败。");
  323. }
  324. }
  325. #endregion
  326. #region 保存用户数据
  327. /// <summary>
  328. /// 保存用户数据
  329. /// </summary>
  330. /// <param name="keyValue"></param>
  331. /// <param name="parentId">单元ID</param>
  332. /// <param name="data">用户数据</param>
  333. /// <param name="roomNo">房间号</param>
  334. /// <param name="bldgId">楼宇ID</param>
  335. /// <param name="areaId">小区ID</param>
  336. /// <param name="meterData">水表数据</param>
  337. /// <returns></returns>
  338. [HttpPost]
  339. [ValidateAntiForgeryToken]
  340. [AjaxOnly]
  341. public ActionResult SaveUserForm(string keyValue, string parentId, string data, string meterData)
  342. {
  343. if (string.IsNullOrEmpty(keyValue))
  344. {
  345. int roomId = bll.SaveUserForm(parentId, data);
  346. //保存表具信息
  347. switch (bll.SaveMeterForm(roomId.ToString(), meterData))
  348. {
  349. case 0:
  350. return Success("保存成功。");
  351. default:
  352. return Error("保存失败。");
  353. }
  354. }
  355. else
  356. {
  357. switch (bll.EditUserForm(parentId, keyValue, data))
  358. {
  359. case 0:
  360. return Error("修改失败。");
  361. case 1:
  362. return Success("修改成功。");
  363. case 2:
  364. return Error("重复数据。");
  365. default:
  366. return Error("修改失败。");
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 批量保存用户数据
  372. /// </summary>
  373. /// <param name="keyValue"></param>
  374. /// <param name="data"></param>
  375. /// <returns></returns>
  376. [HttpPost]
  377. [ValidateAntiForgeryToken]
  378. [AjaxOnly]
  379. public ActionResult SaveBatchUserForm(string parentId, string data)
  380. {
  381. bll.SaveBatchUserForm(parentId, data);
  382. return Success("保存成功。");
  383. }
  384. #endregion
  385. #region 获取用户信息
  386. /// <summary>
  387. /// 获取用户信息
  388. /// </summary>
  389. /// <param name="id"></param>
  390. /// <returns></returns>
  391. public ActionResult GetUserInfo(string id)
  392. {
  393. return Content(bll.GetUserInfo(id));
  394. }
  395. #endregion
  396. #region 删除用户信息
  397. /// <summary>
  398. /// 删除用户信息
  399. /// </summary>
  400. /// <param name="id"></param>
  401. /// <returns></returns>
  402. public ActionResult DeleteUserForm(string id)
  403. {
  404. switch (bll.DeleteUserForm(id))
  405. {
  406. case 2:
  407. return Error("有下级数据,不允许删除。");
  408. case 1:
  409. return Success("删除成功。");
  410. case 0:
  411. return Error("删除失败。");
  412. default:
  413. return Error("删除失败。");
  414. }
  415. }
  416. #endregion
  417. #region 保存表具数据
  418. /// <summary>
  419. /// 保存表具数据
  420. /// </summary>
  421. /// <param name="keyValue"></param>
  422. /// <param name="data"></param>
  423. /// <returns></returns>
  424. [HttpPost]
  425. [ValidateAntiForgeryToken]
  426. [AjaxOnly]
  427. public ActionResult SaveMeterForm(string keyValue, string parentId, string data)
  428. {
  429. if (string.IsNullOrEmpty(keyValue))
  430. {
  431. switch (bll.SaveMeterForm(parentId, data))
  432. {
  433. case 0:
  434. return Success("保存成功。");
  435. case 1:
  436. return Error("保存失败。");
  437. case 2:
  438. return Error("重复数据。");
  439. default:
  440. return Error("保存失败。");
  441. }
  442. }
  443. else
  444. {
  445. switch (bll.EditMeterForm(keyValue, data))
  446. {
  447. case 0:
  448. return Success("保存成功。");
  449. case 1:
  450. return Error("修改失败。");
  451. case 2:
  452. return Error("重复数据。");
  453. default:
  454. return Error("修改失败。");
  455. }
  456. }
  457. }
  458. #endregion
  459. #region 获取表具信息
  460. /// <summary>
  461. /// 保存用户信息
  462. /// </summary>
  463. /// <param name="data"></param>
  464. /// <returns></returns>
  465. public ActionResult GetMeterByMeterId(string keyValue)
  466. {
  467. return Content(bll.GetMeterByMeterId(keyValue).ToJson());
  468. }
  469. #endregion
  470. #region 删除表具信息
  471. /// <summary>
  472. /// 删除表具信息
  473. /// </summary>
  474. /// <param name="id"></param>
  475. /// <returns></returns>
  476. public ActionResult DeleteMeterForm(string id)
  477. {
  478. switch (bll.DeleteMeterForm(id))
  479. {
  480. case 1:
  481. return Success("删除成功。");
  482. case 0:
  483. return Error("删除失败。");
  484. default:
  485. return Error("删除失败。");
  486. }
  487. }
  488. #endregion
  489. /// <summary>
  490. /// 移动表的安装位置
  491. /// </summary>
  492. /// <returns></returns>
  493. public ActionResult RemoveMeterForm()
  494. {
  495. return View();
  496. }
  497. /// <summary>
  498. /// 移动表位置 操作保存
  499. /// </summary>
  500. /// <param name="meterId">表ID</param>
  501. /// <param name="jsonData">新位置JSON</param>
  502. /// <returns></returns>
  503. public ActionResult SaveMeterRemove(string meterId, string jsonData)
  504. {
  505. JObject jsonDataJObj; // jsonData 的JObject 对象
  506. JObject upJobj;//更新结果的 JObject 对象
  507. string areaId; // 区域ID
  508. string bldgId; // 楼宇ID
  509. string apmtId; // 单元ID
  510. string roomId; // 房间ID
  511. if (string.IsNullOrEmpty(meterId) || string.IsNullOrEmpty(jsonData) || "{}".Equals(jsonData))
  512. {
  513. return Error("参数不全!");
  514. }
  515. jsonDataJObj = jsonData.ToJObject();
  516. if (jsonDataJObj["AreaId"] != null && jsonDataJObj["BldgId"] != null && jsonDataJObj["ApmtId"] != null && jsonDataJObj["RoomId"] != null)
  517. {
  518. areaId = jsonDataJObj["AreaId"].ToString();
  519. bldgId = jsonDataJObj["BldgId"].ToString();
  520. apmtId = jsonDataJObj["ApmtId"].ToString();
  521. roomId = jsonDataJObj["RoomId"].ToString();
  522. //验证是否为 INT 类型值
  523. if (ValidateUtil.IsValidInt(meterId) && ValidateUtil.IsValidInt(areaId) && ValidateUtil.IsValidInt(bldgId) && ValidateUtil.IsValidInt(apmtId) && ValidateUtil.IsValidInt(roomId))
  524. {
  525. upJobj = bll.SaveMeterRemove(meterId, areaId, bldgId, apmtId, roomId).ToJObject();
  526. }
  527. else
  528. {
  529. return Error("参数格式错误!");
  530. }
  531. }
  532. else
  533. {
  534. return Error("参数不全!");
  535. }
  536. //失败
  537. if ("0".Equals(upJobj["code"].ToString()))
  538. {
  539. return Error(upJobj["message"].ToString());
  540. }
  541. return Success(upJobj["message"].ToString());
  542. }
  543. }
  544. }