| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.qlm.service.impl;
- import com.jfinal.aop.Before;
- import com.jfinal.kit.JsonKit;
- import com.jfinal.plugin.activerecord.Db;
- import com.jfinal.plugin.activerecord.Record;
- import com.jfinal.plugin.activerecord.tx.Tx;
- import com.qlm.service.IAdminService;
- import com.qlm.tools.JFinalUtil;
- import com.qlm.tools.WxUtil;
- import java.util.List;
- /**
- * @author nommpp
- * @date 2020/3/2
- */
- public class IAdminServiceImpl implements IAdminService {
- @Override
- public String getUsersList() {
- List<Record> users = Db.find("select * from t_admin where status <> 3");
- if(users != null){
- for(Record user:users){
- Record admin_role = Db.findFirst("select * from t_admin_role where userid = ? limit 1", JFinalUtil.getInt("id", user));
- if(admin_role != null){
- Record role = Db.findById("t_role",JFinalUtil.getInt("roleid", admin_role));
- if(role != null){
- user.set("rolename", role.getStr("role_name"));
- }
- }
- }
- }
- return JsonKit.toJson(users);
- }
- @Before(Tx.class)
- @Override
- public boolean save(Record user) {
- boolean result = Db.save("t_admin", user);
- int insert = 0;
- if(result){
- Integer id = WxUtil.getInt("id", user);
- insert = Db.update("insert into t_admin_role (userid,roleid) values (?,?)",id,user.getInt("role"));
- }
- return insert > 0 ?true:false;
- }
- @Override
- public boolean enableUser(Integer id) {
- Record user = Db.findById("t_admin", id);
- if(user == null){
- return false;
- }
- user.set("status", 1);
- return Db.update("t_admin", user);
- }
- @Override
- public boolean disableUser(Integer id) {
- Record user = Db.findById("t_admin", id);
- if(user == null){
- return false;
- }
- user.set("status", 0);
- return Db.update("t_admin", user);
- }
- @Before(Tx.class)
- @Override
- public boolean updateUser(Record user) {
- boolean result = Db.update("t_admin", user);
- int insert = 0;
- if(result){
- insert = Db.update("update t_admin_role set roleid = ? where userid = ?",user.getInt("role"),user.getInt("id"));
- }
- return insert > 0 ?true:false;
- }
- @Before(Tx.class)
- @Override
- public boolean delUser(Integer id) {
- Record user = Db.findById("t_admin", id);
- if(user == null){
- return false;
- }
- user.set("status", 3);
- Db.update("delete from t_admin_role where userid = ?",id);
- return Db.update("t_admin", user);
- }
- @Override
- public Record getUserById(Integer id) {
- return Db.findById("t_admin", id);
- }
- }
|