package com.saye.hrs.controller;

import javax.annotation.Resource;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.saye.hrs.commons.log.ExceptionDUtil;
import com.saye.hrs.commons.log.LogUtil;
import com.saye.hrs.commons.page.PageUtil;
import com.saye.hrs.commons.page.TemplatePage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.saye.hrs.service.OfficeService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.ui.ModelMap;

/**
 * 
 *
 * @author dqzhang
 * @since 2021-09-16 08:46:32
 */
@RequestMapping("office")
@Controller
public class OfficeController {
   
    @Resource
    private OfficeService officeService;

    /**
     * 跳转页面
     * @param  modelMap
     * @param 
     * @return 
     */
    @RequestMapping("/toOffice")
	public String toUserManager(ModelMap modelMap){

		//查询所有角色
		return "hospital/office";
	}
    /**
     * 分页查询列表
     * @param
     * @param 
     * @return 查询结果
     */
    @RequestMapping("/findOfficePageList")
    @ResponseBody
    public TemplatePage findOfficePageList() {
        HashMap<Object,Object> map=new HashMap<Object,Object>();
        List<HashMap<Object, Object>> list = this.officeService.findOfficeList(map);
        TemplatePage templetJson = new TemplatePage();
        templetJson.setCode(0);
        templetJson.setMsg("");
        templetJson.setData(list);
        templetJson.setCount(list.size());
        return templetJson;
    }

    /**
     * 通过主键查询单条数据
     * @param map
     * @return 单条数据
     */
    @RequestMapping("/findOfficeById")
    @ResponseBody
    public HashMap<Object,Object> findOfficeById(@RequestBody HashMap<Object,Object> map) {
        return this.officeService.findOfficeById(map);
    }

    /**
     * 新增数据
     * @param map
     * @return map
     */
    @RequestMapping("/insertOffice")
    @ResponseBody
    public HashMap<Object,Object> insertOffice(@RequestBody HashMap<Object,Object> map) {
        String errCode = "0";
        String errMsg = "";
        try{  
            this.officeService.insertOffice(map);
        } catch (Exception e) {
            errCode = "999";
            errMsg = "新增失败";
			LogUtil.error(this.getClass(), "新增失败，原因:"+ExceptionDUtil.getDetailExceptionMsg(e));
		}
		HashMap<Object,Object> resultMap = new HashMap<Object,Object>();
		resultMap.put("errCode",errCode);
		resultMap.put("errMsg",errMsg);
		return resultMap;
    }

    /**
     * 编辑数据
     * @param map
     * @return map
     */
    @RequestMapping("/updateOffice")
    @ResponseBody
    public HashMap<Object,Object> updateOffice(@RequestBody HashMap<Object,Object> map) {
        String errCode = "0";
        String errMsg = "";
        try{  
            this.officeService.updateOffice(map);
        } catch (Exception e) {
            errCode = "999";
            errMsg = "修改失败";
			LogUtil.error(this.getClass(), "修改失败，原因:"+ExceptionDUtil.getDetailExceptionMsg(e));
		}
		HashMap<Object,Object> resultMap = new HashMap<Object,Object>();
		resultMap.put("errCode",errCode);
		resultMap.put("errMsg",errMsg);
		return resultMap;
    }

    /**
     * 删除数据
     * @param map
     * @return map
     */
    @RequestMapping("/deleteOfficeById")
    @ResponseBody
    public HashMap<Object,Object> deleteOfficeById(@RequestBody HashMap<Object,Object> map) {
        String errCode = "0";
        String errMsg = "";
        try{  
            this.officeService.deleteOfficeById(map);
        } catch (Exception e) {
            errCode = "999";
            errMsg = "删除失败";
			LogUtil.error(this.getClass(), "删除失败，原因:"+ExceptionDUtil.getDetailExceptionMsg(e));
		}
		HashMap<Object,Object> resultMap = new HashMap<Object,Object>();
		resultMap.put("errCode",errCode);
		resultMap.put("errMsg",errMsg);
        return resultMap;
    }

    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("aaa");
        list.add(0,"dsa");
        System.out.println(list);
    }
}

