admin
2021-03-10 d98c8bd9d1d4f749bd59aa2d3e0905db28c394a6
src/main/java/com/yeshi/buwan/controller/admin/login/LoginController.java
@@ -1,11 +1,16 @@
package com.yeshi.buwan.controller.admin.login;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.yeshi.buwan.domain.system.SystemInfo;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.util.SystemUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -14,7 +19,7 @@
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.AdminInfo;
import com.yeshi.buwan.service.imp.AdminUserService;
import com.yeshi.buwan.service.imp.ConfigService;
import com.yeshi.buwan.service.imp.DetailSystemConfigService;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.StringUtil;
@@ -25,9 +30,12 @@
public class LoginController {
    @Resource
    private ConfigService configService;
    private DetailSystemConfigService configService;
    @Resource
    private AdminUserService adminUserService;
    @Resource
    private SystemService systemService;
    @RequestMapping("adminLogin")
    public void adminLogin(String username, String pwd, String code, HttpServletRequest request, PrintWriter out) {
@@ -65,6 +73,7 @@
                return;
            } else {
                request.getSession().setAttribute(Constant.ADMIN, info);
                SystemUtil.saveAdminSelectedSystem(request.getSession(), getSelectedSystem(request.getSession()));
                // MailSenderUtil.sendEmail("1101184511@qq.com", "影音后台登录",
                // username.trim() + "--" + "登录成功 IP:"
                // + IPUtil.getRemotIP(request) + "--" +
@@ -90,13 +99,91 @@
        AdminInfo info = (AdminInfo) request.getSession().getAttribute(Constant.ADMIN);
        JSONObject json = new JSONObject();
        if (info != null) {
            List<SystemInfo> systemInfoList = systemService.getSystemList();
            SystemInfo system = getSelectedSystem(request.getSession());
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
            json.put("code", "0");
            json.put("info", gson.toJson(info));
            List<SystemInfoAdminVO> systemInfoAdminVOS = new ArrayList<>();
            for (SystemInfo systemInfo : systemInfoList) {
                systemInfoAdminVOS.add(new SystemInfoAdminVO(systemInfo.getId(), systemInfo.getName(), systemInfo.getId().equalsIgnoreCase(system.getId())));
            }
            json.put("systems", new Gson().toJson(systemInfoAdminVOS));
        } else {
            json.put("code", "1");
        }
        out.print(json);
    }
    @RequestMapping("selectSystem")
    public void selectSystem(HttpServletRequest request, String system, PrintWriter out) {
        SystemInfo systemInfo = systemService.getSystem(system);
        if (systemInfo == null) {
            JSONObject json = new JSONObject();
            json.put("code", "1");
            json.put("error", "系统不存在");
            out.print(json);
        } else {
            saveSelectedSystem(request.getSession(), systemInfo);
            JSONObject json = new JSONObject();
            json.put("code", "0");
            out.print(json);
        }
    }
    private SystemInfo getSelectedSystem(HttpSession session) {
        SystemInfo systemInfo = SystemUtil.getAdminSelectedSystem(session);
        if (systemInfo == null) {
            List<SystemInfo> systemInfoList = systemService.getSystemList();
            systemInfo = systemInfoList.get(0);
        }
        return systemInfo;
    }
    private void saveSelectedSystem(HttpSession session, SystemInfo systemInfo) {
        SystemUtil.saveAdminSelectedSystem(session, systemInfo);
    }
    static class SystemInfoAdminVO {
        private String id;
        private String name;
        private boolean selected;
        public SystemInfoAdminVO(String id, String name, boolean selected) {
            this.id = id;
            this.name = name;
            this.selected = selected;
        }
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public boolean isSelected() {
            return selected;
        }
        public void setSelected(boolean selected) {
            this.selected = selected;
        }
    }
}