package com.pqs9900.controller.root;

import com.njcn.pojo.commons.HttpResult;
import com.njcn.pojo.system.SubSystem;
import com.njcn.service.system.SystemService;
import com.njcn.utils.PubUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hongawen
 * @date: 2019/10/8 10:00
 */
@Controller
@RequestMapping("manageSystem")
public class SystemController {
    private static final Logger logger = LoggerFactory.getLogger(SystemController.class);

    @Resource
    private SystemService systemService;


    /**
     * 获取所有子项目系统信息
     */
    @PostMapping("getSystemInfo")
    @ResponseBody
    public HttpResult getSystemInfo(){
        HttpResult httpResult;
        List<SubSystem> subSystemList;
        try{
            subSystemList=systemService.getSystems();
            httpResult= PubUtils.assignmentResult(subSystemList,200,"获取所有系统项目成功");
        }catch(Exception e){
            logger.error(e.toString());
            httpResult= PubUtils.assignmentResult(null,500,"获取所有系统项目失败");
        }
        return httpResult;
    }

    /**
     * 隐藏当前系统
     */
    @PostMapping("hideSystem")
    @ResponseBody
    public HttpResult hideSystem(String systemIndex){
        HttpResult httpResult;
        try{
            systemService.hideSystem(systemIndex);
            httpResult= PubUtils.assignmentResult(null,200,"隐藏系统项目成功");
        }catch(Exception e){
            logger.error(e.toString());
            httpResult= PubUtils.assignmentResult(null,500,"隐藏系统项目失败");
        }
        return httpResult;
    }

    /**
     * 显示当前系统
     */
    @PostMapping("displaySystem")
    @ResponseBody
    public HttpResult displaySystem(String systemIndex){
        HttpResult httpResult;
        try{
            systemService.displaySystem(systemIndex);
            httpResult= PubUtils.assignmentResult(null,200,"显示系统项目成功");
        }catch(Exception e){
            logger.error(e.toString());
            httpResult= PubUtils.assignmentResult(null,500,"显示系统项目失败");
        }
        return httpResult;
    }


    /**
     * 隐藏当前系统
     */
    @PostMapping("defaultSystem")
    @ResponseBody
    public HttpResult defaultSystem(String systemIndex){
        HttpResult httpResult;
        try{
            systemService.defaultSystem(systemIndex);
            httpResult= PubUtils.assignmentResult(null,200,"设置默认系统项目成功");
        }catch(Exception e){
            logger.error(e.toString());
            httpResult= PubUtils.assignmentResult(null,500,"设置默认系统项目失败");
        }
        return httpResult;
    }




}
