package com.yeshi.location.app.controller.admin; import com.yeshi.location.app.entity.SystemEnum; import com.yeshi.location.app.service.inter.AdminUserService; import com.yeshi.location.app.utils.SystemInfoUtil; import com.yeshi.location.app.vo.SystemVO; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.yeshi.utils.JsonUtil; import javax.annotation.Resource; import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.List; @Controller @RequestMapping("/admin/api/system") public class SystemController { @Resource private AdminUserService adminUserService; @ResponseBody @RequestMapping("systemList") public String systemList(HttpSession session) { List systemVOList = new ArrayList<>(); SystemVO selected = null; for (SystemEnum system : SystemEnum.values()) { SystemVO systemVO = new SystemVO(system.getName(), system.name(), system == SystemInfoUtil.getAdminSelectedSystem(session)); if (systemVO.isSelected()) { selected = systemVO; } systemVOList.add(systemVO); } if (selected == null) { systemVOList.get(0).setSelected(true); SystemInfoUtil.saveAdminSelectedSystem(session, SystemEnum.valueOf(systemVOList.get(0).getKey())); } JSONObject data = new JSONObject(); data.put("count", systemVOList.size()); data.put("list", systemVOList); return JsonUtil.loadTrueResult(data); } @ResponseBody @RequestMapping("selectSystem") public String selectSystem(String key, HttpSession session) { if (SystemEnum.valueOf(key) == null) { return JsonUtil.loadFalseResult("选择失败,系统不存在"); } SystemInfoUtil.saveAdminSelectedSystem(session, SystemEnum.valueOf(key)); return JsonUtil.loadTrueResult(""); } }