package com.controller.admin;


import com.controller.CommonController;
import com.entity.ResourcesType;
import com.service.ResourcesTypeService;
import com.service.UsersService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

/**
 *  应急资源分类控制类
 * @ignore
 * @Author:Alcedo QQ:815657032
 * @Date 2020/4/15 11:05
 */
@Controller
@RequestMapping("/admin/")
public class ResourcesTypeController {
    @Resource
    private ResourcesTypeService resourcesTypeService;
    @Resource
    private UsersService usersService;

    @Resource
    private CommonController commonController;
    /*设置访问路径*/
    private String path="admin/views/resources_type/";



    public static final String TABLE_NAME = "分类";



    /**
     * ===后台分类管理===
     *
     * @return
     */

    /*处理添加分类*/
    @RequestMapping("doAddResourcesType.do")
    public String doAddResourcesType(HttpServletRequest request, ModelMap map) {
        /*通用方法*/
        commonController.commonMethod(map);
        return path+"resourcesType_add";
    }

    // 添加分类
    @RequestMapping("addResourcesType.do")
	public String addResourcesType(HttpServletRequest request,ResourcesType resourcesType, HttpSession session){
            resourcesTypeService.add(resourcesType);
        return "redirect:resourcesTypeList.do";
	}




    /*处理修改分类*/
    @RequestMapping("doUpdateResourcesType.do")
    public String doUpdateResourcesType(HttpServletRequest request, int id, ModelMap map) {
        map.put("resourcesType", resourcesTypeService.getById(id));
        /*通用方法*/
        commonController.commonMethod(map);
        return path+"resourcesType_update";
    }

    /*查看分类*/
    @RequestMapping("doLookResourcesType.do")
    public String doLookResourcesType(HttpServletRequest request, int id, ModelMap map) {
        map.put("resourcesType", resourcesTypeService.getById(id));
        /*通用方法*/
        commonController.commonMethod(map);
        return path+"resourcesType_look";
    }

    /*保存分类*/
    @RequestMapping("updateResourcesType.do")
    public String updateResourcesType(HttpServletRequest request,ResourcesType resourcesType) {
        resourcesTypeService.update(resourcesType);
        return "redirect:resourcesTypeList.do";
    }


    // 分页查询分类信息的列表
    @RequestMapping("resourcesTypeList.do")
    public String resourcesTypeList(@RequestParam(value = "page", defaultValue = "0") Integer page, ModelMap map,
                            HttpSession session) {
        Map<String, Object> bMap = new HashMap<>();

        List<ResourcesType> list = resourcesTypeService.getAll(bMap);
        map.put("list", list);
        /*通用方法*/
        commonController.commonMethod(map);
        return path+"resourcesType_list";
    }

    // 分页查询分类信息的列表--模糊查询
    @RequestMapping("resourcesTypeListSearch.do")
    public String resourcesTypeListSearch(@RequestParam(value = "page", defaultValue = "0") Integer page, ModelMap map,
                                  HttpSession session, ResourcesType resourcesType) {
        Map<String, Object> bMap = new HashMap<>();

        if (resourcesType.getName() != null && !resourcesType.getName().equals("")) {
            bMap.put("name",resourcesType.getName());
        }
        List<ResourcesType> list = resourcesTypeService.getAll(bMap);
        map.put("list", list);
        /*通用方法*/
        commonController.commonMethod(map);
        return path+"resourcesType_list";
    }

    /*删除分类*/
    @RequestMapping("deleteResourcesType.do")
    public String deleteResourcesType(int id) {
        resourcesTypeService.delete(id);
        return "redirect:resourcesTypeList.do";
    }

}

