package com.happy.action;

import com.alibaba.fastjson.JSONArray;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.happy.Model.*;
import com.happy.Model.AdminManager;
import com.happy.Until.GetHttpParam;
import com.happy.Until.PwdDefind;
import com.happy.Until.ResUtil;
import com.happy.Until.UUIDUtil;
import com.happy.dto.IPage;
import com.happy.dto.townshipCountDTO;
import com.happy.service.*;
import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List;
import java.util.UUID;

public class adminManagerAction extends ActionSupport implements ServletRequestAware{

    private HttpServletRequest request;
    public HttpServletResponse response;

    @Resource
    public AdminService adminService;

    @Resource
    public AdminManagerService adminManagerService;

    @Resource
    public HotelService hotelService;

    @Resource
    public BookService bookService;

    @Resource
    public FileService fileService;

    public String adminName;
    public String password;
    public String hotelTownship;
    public Integer managerId;//商户Id
    public Integer id;
    public String level;//权限
    public int page; // 当前页
    public int rows;// 每页显示的行数rows

    public String fileListJson;

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    /**
     * 描述：登录
     * @return
     */
    public String loginAdmin() {
        JSONObject resultJson = new JSONObject();
        StringBuilder getOneSqlx = new StringBuilder("");
        getOneSqlx.append(" and admin_name = '").append(adminName).append("'");
        AdminManager login = adminManagerService.getOen(getOneSqlx.toString());

        StringBuilder getOneSqlx1 = new StringBuilder("");
        getOneSqlx1.append(" and admin_name = '").append(adminName).append("'")
                .append(" and password = '").append(password).append("'");
        AdminManager login1 = adminManagerService.getOen(getOneSqlx1.toString());
        if (login != null) {
            if(login1 == null){
                resultJson.put("message", "用户名或密码错误");
                resultJson.put("code", 205);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if(login.getStatus()==2){
                resultJson.put("message", "账号已冻结请联系管理员");
                resultJson.put("code", 205);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }else{
                //是否主账号首次登录
                Hotel hotel = hotelService.getOen("and manager_id = "+login.getManagerId()+"");
                if(hotel.getHposition()==null && "2".equals(login.getLevel())){
                    resultJson.put("isLogin",1);
                }else{
                    resultJson.put("isLogin",0);
                }
                login.setPassword("********");
                resultJson.put("message", "登录成功");
                resultJson.put("code", 200);
                resultJson.put("data", login);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
        }
        resultJson.put("message", "该账户不存在");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }

    /**
     * 描述：新增管理端民宿账号
     * @return
     */
    public String insertAdmin() {

        JSONObject resultJson = new JSONObject();
        Gson gson = new Gson();
        com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
        if (json == null) {
            resultJson.put("message", "请传入参数");
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = null;
        try {
            admin = gson.fromJson(json.toString(), new TypeToken<AdminManager>() {}.getType());

            if (admin == null) {
                resultJson.put("message", "数据为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }

            if (admin.getAdminName()==null || admin.getHotelName()==null || admin.getHotelTownship()==null || "".equals(admin.getHotelTownship())
                    || admin.getLevel()==null || admin.getCardName()==null || admin.getCorpnPhone()==null){
                resultJson.put("message", "各参数不能为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if (!PwdDefind.vertify(admin.getPassword())){
                resultJson.put("message", "密码至少包含：大小写英文字母、数字、特殊符号,密码长度大于8位,小于20位");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            StringBuilder getOneSqlx = new StringBuilder("");
            getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'");
            AdminManager listc = adminManagerService.getOen(getOneSqlx.toString());
            if (listc != null) {
                resultJson.put("message", "该用户已存在");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            admin.setId(Math.toIntExact(UUIDUtil.generateID()));
            admin.setManagerId(admin.getId());
            //保存详细图附件
            List<FileInfo> fileInfoList = JSONArray.parseArray(fileListJson, FileInfo.class);
            if(fileInfoList!=null && fileInfoList.size()>0){
                for(FileInfo file : fileInfoList){
                    file.setLinkId(String.valueOf(admin.getId()));
                    file.setId(String.valueOf(UUID.randomUUID()));
                    int lastSlashIndex = file.getUrl().lastIndexOf("/");
                    if(lastSlashIndex >= 0){
                        String result = file.getUrl().substring(lastSlashIndex + 1);
                        file.setName(result);
                    }
                    fileService.insertFile(file);
                }
            }
            int m = adminManagerService.insertAdmin(admin);
            //region 往hotel表中插入一条数据关联admin_manager
            Hotel hotel = new Hotel();
            hotel.setManagerId(admin.getManagerId());
            hotel.setHname(admin.getHotelName());
            hotel.setStatus(1);
            hotel.setHstatus(2);
            int i = hotelService.insertHotel(hotel);
            //endregion
            if (m > 0 && i > 0) {
                resultJson.put("message", "添加成功");
                resultJson.put("code", 200);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            } else {
                resultJson.put("message", "添加失败");
                resultJson.put("code", 502);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        resultJson.put("message", "未知异常");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }

    /**
     * 描述：修改管理端民宿账号
     * @return
     */
    public String updateAdmin() {

        JSONObject resultJson = new JSONObject();
        Gson gson = new Gson();
        com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
        if (json == null) {
            resultJson.put("message", "请传入参数");
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = null;
        try {
            admin = gson.fromJson(json.toString(), new TypeToken<AdminManager>() {}.getType());
            if (admin == null) {
                resultJson.put("message", "数据为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if(admin.getId()==null){
                resultJson.put("message", "修改用户Id不能为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if (admin.getAdminName()==null || admin.getCorpnName()==null || admin.getHotelTownship()==null || "".equals(admin.getHotelTownship())
                    || admin.getLevel()==null || admin.getCardName()==null || admin.getCorpnPhone()==null){
                resultJson.put("message", "各参数不能为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if(admin.getPassword()!=null && !"".equals(admin.getPassword())){
                if (!PwdDefind.vertify(admin.getPassword())){
                    resultJson.put("message", "密码至少包含：大小写英文字母、数字、特殊符号,密码长度大于8位,小于20位");
                    resultJson.put("code", 500);
                    ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                    return null;
                }
            }
            StringBuilder getOneSqlx = new StringBuilder("");
            getOneSqlx.append(" and a.admin_name = '").append(admin.getAdminName()).append("'");
            getOneSqlx.append(" and a.id != '").append(admin.getId()).append("'");
            AdminManager listc = adminManagerService.getOen(getOneSqlx.toString());
            if (listc != null) {
                resultJson.put("message", "该用户已存在");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            //修改详细图附件
            List<FileInfo> fileInfoList = JSONArray.parseArray(fileListJson, FileInfo.class);
            if(fileInfoList!=null && fileInfoList.size()>0){
                if(admin.getId()!= null){
                    fileService.delLinkFile(String.valueOf(admin.getId()));
                }
                for(FileInfo file : fileInfoList){
                    FileInfo fileInfo = fileService.getById(file.getId());
                    file.setLinkId(String.valueOf(admin.getId()));
                    if(fileInfo==null){
                        fileService.insertFile(file);
                    }else{
                        fileService.updateFile(file);
                    }
                }
            }
            int m = adminManagerService.updateAdmin(admin);
            if (m > 0) {
                resultJson.put("message", "修改成功");
                resultJson.put("code", 200);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            } else {
                resultJson.put("message", "修改失败");
                resultJson.put("code", 502);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        resultJson.put("message", "未知异常");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }

    /**
     * 描述：新增民宿端普通账号
     * @return
     */
    public String insertAdminManager() {
        JSONObject resultJson = new JSONObject();
        Gson gson = new Gson();
        com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
        if (json == null) {
            resultJson.put("message", "请传入参数");
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = null;
        try {
            admin = gson.fromJson(json.toString(), new TypeToken<AdminManager>() {}.getType());
            if (admin == null) {
                resultJson.put("message", "数据为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if (admin.getAdminName()==null || admin.getCorpnName()==null || admin.getCorpnPhone()==null
                    || admin.getLevel()==null || admin.getPassword()==null){
                resultJson.put("message", "各参数不能为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if(admin.getManagerId()==null){
                resultJson.put("message", "民宿超级管理员Id不能为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if (!PwdDefind.vertify(admin.getPassword())){
                resultJson.put("message", "密码至少包含：大小写英文字母、数字、特殊符号,密码长度大于8位,小于20位");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            StringBuilder getOneSqlx = new StringBuilder("");
            getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'");
            AdminManager listc = adminManagerService.getOen(getOneSqlx.toString());
            if (listc != null) {
                resultJson.put("message", "该用户已存在");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            int m = adminManagerService.insertAdmin(admin);
            if (m > 0) {
                resultJson.put("message", "添加成功");
                resultJson.put("code", 200);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            } else {
                resultJson.put("message", "添加失败");
                resultJson.put("code", 502);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        resultJson.put("message", "未知异常");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }

    /**
     * 描述：修改民宿端普通账号
     * @return
     */
    public String updateAdminManager() {
        JSONObject resultJson = new JSONObject();
        Gson gson = new Gson();
        com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
        if (json == null) {
            resultJson.put("message", "请传入参数");
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = null;
        try {
            admin = gson.fromJson(json.toString(), new TypeToken<AdminManager>() {}.getType());
            if (admin == null) {
                resultJson.put("message", "数据为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if (admin.getId()==null){
                resultJson.put("message", "用户主键不能为空");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            if (admin.getPassword()!=null && !"".equals(admin.getPassword()) && !PwdDefind.vertify(admin.getPassword())){
                resultJson.put("message", "密码至少包含：大小写英文字母、数字、特殊符号,密码长度大于8位,小于20位");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            StringBuilder getOneSqlx = new StringBuilder("");
            getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'");
            getOneSqlx.append(" and id != '").append(admin.getId()).append("'");
            AdminManager listc = adminManagerService.getOen(getOneSqlx.toString());
            if (listc != null) {
                resultJson.put("message", "该用户已存在");
                resultJson.put("code", 500);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
            int m = adminManagerService.updateAdmin(admin);
            if (m > 0) {
                resultJson.put("message", "修改成功");
                resultJson.put("code", 200);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            } else {
                resultJson.put("message", "修改失败");
                resultJson.put("code", 502);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        resultJson.put("message", "未知异常");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }

    /**
     * 描述：删除
     * @return
     */
    public String delAdmin(){
        JSONObject resultJson = new JSONObject();
        if (id == null) {
            resultJson.put("message", "请传入id");
            resultJson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = adminManagerService.getById(id);
        StringBuilder booksql = new StringBuilder("");
        booksql.append(" and hotel_manager_id = '").append(admin.getManagerId()).append("'");
        booksql.append(" and order_status in (1,2,3,4,10) ");
        List<Booking> bookingList = bookService.queryList(booksql.toString());
        if(bookingList!=null && bookingList.size()>0){
            resultJson.put("message", "该民宿存在未完成的订单，禁止删除");
            resultJson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        int m = adminManagerService.delAdmin(id);
        if (m > 0) {
            //冻结旗下所有民宿、账号
            if(admin.getManagerId()!=null){
                //民宿
                Hotel hotel = hotelService.getByManagerId(admin.getManagerId());
                if(hotel!=null){
                    hotel.setStatus(0);
                    hotelService.updateHotel(hotel);
                }
                //员工账号
                StringBuilder managersql = new StringBuilder("");
                managersql.append(" and manager_id = '").append(admin.getManagerId()).append("'");
                managersql.append(" and level = 1 ");
                List<AdminManager> managerList = adminManagerService.queryList(managersql.toString());
                if(managerList!=null){
                    for(AdminManager manager : managerList){
                        manager.setStatus(0);
                        adminManagerService.updateAdmin(manager);
                    }
                }
            }
            resultJson.put("message", "删除成功");
            resultJson.put("code", 200);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        resultJson.put("message", "未知异常");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }

    /**
     * 描述：重置密码
     * @return
     */
    public String removePwd(){
        JSONObject resultJson = new JSONObject();
        if (id == null) {
            resultJson.put("message", "请传入id");
            resultJson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = adminManagerService.getById(id);
        if (admin != null && !"".equals(admin)) {
            admin.setPassword("Jams_123456");
            int m = adminManagerService.updateAdmin(admin);
            if(m > 0){
                resultJson.put("message", "重置成功");
                resultJson.put("code", 200);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }else{
                resultJson.put("message", "重置失败");
                resultJson.put("code", 502);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
        }
        resultJson.put("message", "未知异常");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }
    /**
     * 描述：冻结账号
     * @return
     */
    public String freezeAdmin(){
        JSONObject resultJson = new JSONObject();
        if (id == null) {
            resultJson.put("message", "请传入id");
            resultJson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = adminManagerService.getById(id);
        if (admin != null && !"".equals(admin)) {
            //冻结旗下所有民宿、账号
            if(admin.getManagerId()!=null){
                //民宿
                Hotel hotel = hotelService.getByManagerId(admin.getManagerId());
                if(hotel!=null){
                    hotel.setStatus(2);
                    hotelService.updateHotel(hotel);
                }
                //员工账号
                StringBuilder managersql = new StringBuilder("");
                managersql.append(" and manager_id = '").append(admin.getManagerId()).append("'");
                managersql.append(" and level = 1 ");
                List<AdminManager> managerList = adminManagerService.queryList(managersql.toString());
                if(managerList!=null){
                    for(AdminManager manager : managerList){
                        manager.setStatus(2);
                        adminManagerService.updateAdmin(manager);
                    }
                }
            }
            admin.setStatus(2);
            int m = adminManagerService.updateAdmin(admin);
            if(m > 0){
                resultJson.put("message", "冻结成功");
                resultJson.put("code", 200);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }else{
                resultJson.put("message", "冻结失败");
                resultJson.put("code", 502);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
        }
        resultJson.put("message", "未知异常");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }
    /**
     * 描述：解冻账号
     * @return
     */
    public String thawAdmin(){
        JSONObject resultJson = new JSONObject();
        if (id == null) {
            resultJson.put("message", "请传入id");
            resultJson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = adminManagerService.getById(id);
        if (admin != null && !"".equals(admin)) {
            //冻结旗下所有民宿、账号
            if(admin.getManagerId()!=null){
                //民宿
                Hotel hotel = hotelService.getByManagerId(admin.getManagerId());
                if(hotel!=null){
                    hotel.setStatus(1);
                    hotelService.updateHotel(hotel);
                }
                //员工账号
                StringBuilder managersql = new StringBuilder("");
                managersql.append(" and manager_id = '").append(admin.getManagerId()).append("'");
                managersql.append(" and level = 1 ");
                List<AdminManager> managerList = adminManagerService.queryList(managersql.toString());
                if(managerList!=null){
                    for(AdminManager manager : managerList){
                        manager.setStatus(1);
                        adminManagerService.updateAdmin(manager);
                    }
                }
            }
            admin.setStatus(1);
            int m = adminManagerService.updateAdmin(admin);
            if(m > 0){
                resultJson.put("message", "解冻成功");
                resultJson.put("code", 200);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }else{
                resultJson.put("message", "解冻成功");
                resultJson.put("code", 502);
                ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                return null;
            }
        }
        resultJson.put("message", "未知异常");
        resultJson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        return null;
    }


    /**
     * 描述：分页查询
     * @return
     */
    public String queryPage(){
        JSONObject resultJson = new JSONObject();
        StringBuilder s1 = new StringBuilder("");
        if (adminName!=null){
            s1.append(" and ( admin_name like '%").append(adminName).append("%'")
                .append(" or hotel_name like '%").append(adminName).append("%'")
                .append(" or corpn_name like '%").append(adminName).append("%'")
                .append(" or corpn_phone like '%").append(adminName).append("%')");
        }
        if (hotelTownship!=null){
            s1.append(" and hotel_township = '").append(hotelTownship).append("'");
        }
        if(managerId!=null){
            s1.append(" and manager_id = ").append(managerId);
        }
        if(level!=null){
            s1.append(" and level = '").append(level).append("'");
        }
        IPage<AdminManager> adminIPage = adminManagerService.queryPage(s1.toString(),page,rows);
        if(adminIPage!=null && !"".equals(adminIPage)){
            resultJson.put("message", "查询分页成功");
            resultJson.put("code", 200);
            resultJson.put("data", adminIPage);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        }else{
            resultJson.put("message", "查询分页失败");
            resultJson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
        }
        return null;
    }

    /**
     * 描述：根据Id查询详细
     * @return
     */
    public String getById(){
        JSONObject resultJson = new JSONObject();
        if (id == null) {
            resultJson.put("message", "请传入id");
            resultJson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
        AdminManager admin = adminManagerService.getById(id);
        List<FileInfo> fileInfoList = fileService.queryList("and link_id ='"+id+"'");
        admin.setFileInfoList(fileInfoList);
        if (admin != null) {
            resultJson.put("message", "查询成功");
            resultJson.put("code", 200);
            resultJson.put("data", admin);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }else{
            resultJson.put("message", "未查到用户信息");
            resultJson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
            return null;
        }
    }

    /**
     * 描述：查询菜单
     * @return
     */
    public String getIndexList(){
        JSONObject resultjson = new JSONObject();
        StringBuilder s1 = new StringBuilder("");
        if (id==null){
            resultjson.put("message", "请传入用户Id");
            resultjson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
            return null;
        }
        AdminManager admin = adminManagerService.getById(id);
        if (admin==null){
            resultjson.put("message", "未查到用户信息");
            resultjson.put("code", 500);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
            return null;
        }
        String ids = admin.getAdminPower();
        s1.append(" and id in (").append(ids).append(") ");
        List<AdminPower> lpower = adminService.queryTree(s1.toString());
        if (lpower!=null){
            resultjson.put("message", "返回成功");
            resultjson.put("code", 200);
            resultjson.put("data",lpower);
            ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
            return null;
        }
        resultjson.put("message", "数据为空");
        resultjson.put("code", 205);
        ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
        return null;
    }

}
