IAdminServiceImpl.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.qlm.service.impl;
  2. import com.jfinal.aop.Before;
  3. import com.jfinal.kit.JsonKit;
  4. import com.jfinal.plugin.activerecord.Db;
  5. import com.jfinal.plugin.activerecord.Record;
  6. import com.jfinal.plugin.activerecord.tx.Tx;
  7. import com.qlm.service.IAdminService;
  8. import com.qlm.tools.JFinalUtil;
  9. import com.qlm.tools.WxUtil;
  10. import java.util.List;
  11. /**
  12. * @author nommpp
  13. * @date 2020/3/2
  14. */
  15. public class IAdminServiceImpl implements IAdminService {
  16. @Override
  17. public String getUsersList() {
  18. List<Record> users = Db.find("select * from t_admin where status <> 3");
  19. if(users != null){
  20. for(Record user:users){
  21. Record admin_role = Db.findFirst("select * from t_admin_role where userid = ? limit 1", JFinalUtil.getInt("id", user));
  22. if(admin_role != null){
  23. Record role = Db.findById("t_role",JFinalUtil.getInt("roleid", admin_role));
  24. if(role != null){
  25. user.set("rolename", role.getStr("role_name"));
  26. }
  27. }
  28. }
  29. }
  30. return JsonKit.toJson(users);
  31. }
  32. @Before(Tx.class)
  33. @Override
  34. public boolean save(Record user) {
  35. boolean result = Db.save("t_admin", user);
  36. int insert = 0;
  37. if(result){
  38. Integer id = WxUtil.getInt("id", user);
  39. insert = Db.update("insert into t_admin_role (userid,roleid) values (?,?)",id,user.getInt("role"));
  40. }
  41. return insert > 0 ?true:false;
  42. }
  43. @Override
  44. public boolean enableUser(Integer id) {
  45. Record user = Db.findById("t_admin", id);
  46. if(user == null){
  47. return false;
  48. }
  49. user.set("status", 1);
  50. return Db.update("t_admin", user);
  51. }
  52. @Override
  53. public boolean disableUser(Integer id) {
  54. Record user = Db.findById("t_admin", id);
  55. if(user == null){
  56. return false;
  57. }
  58. user.set("status", 0);
  59. return Db.update("t_admin", user);
  60. }
  61. @Before(Tx.class)
  62. @Override
  63. public boolean updateUser(Record user) {
  64. boolean result = Db.update("t_admin", user);
  65. int insert = 0;
  66. if(result){
  67. insert = Db.update("update t_admin_role set roleid = ? where userid = ?",user.getInt("role"),user.getInt("id"));
  68. }
  69. return insert > 0 ?true:false;
  70. }
  71. @Before(Tx.class)
  72. @Override
  73. public boolean delUser(Integer id) {
  74. Record user = Db.findById("t_admin", id);
  75. if(user == null){
  76. return false;
  77. }
  78. user.set("status", 3);
  79. Db.update("delete from t_admin_role where userid = ?",id);
  80. return Db.update("t_admin", user);
  81. }
  82. @Override
  83. public Record getUserById(Integer id) {
  84. return Db.findById("t_admin", id);
  85. }
  86. }