/**
* 文件：ResourceController.java
* 版本：1.0.0
* 日期：
* Copyright &reg; 
* All right reserved.
*/
package com.mortals.xhx.base.system.resource.web;


import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.UserType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.common.code.AuthType;
import com.mortals.xhx.common.code.SourceType;

/**
 * <p>Title: 资源信息</p>
 * <p>Description: ResourceController  </p>
 * <p>Copyright: Copyright &reg;  </p>
 * <p>Company: </p>
 * @author 
 * @version 1.0.0
 */
@RestController
@RequestMapping("resource")
public class ResourceController extends BaseCRUDJsonMappingController<ResourceService,ResourceForm,ResourceEntity,Long> {

	public ResourceController(){
		super.setFormClass(ResourceForm.class);
		super.setModuleDesc("资源信息");
	}

	@Override
	protected void init(HttpServletRequest request, HttpServletResponse response, ResourceForm form,
						Map<String, Object> model, Context context) {
		Map<String, Object> statsus = new HashMap<String, Object>();
		statsus.put("authType", AuthType.getEnumMap());
		statsus.put("sourceType", SourceType.getEnumMap());
		if (getCurUser().isAdmin()) {
			statsus.put("userType",  IBaseEnum.getEnumMap(UserType.class));
		} else {
			statsus.put("userType", UserType.findByValue(getCurUser().getUserType()));
		}
		model.put(KEY_RESULT_DICT, statsus);
		super.init(request, response, form, model, context);
	}

	/**
	 * 获取所有资源
	 *
	 * @return
	 */
	@PostMapping("allResources")
	public String allResources(int userType) {
		JSONObject ret = new JSONObject();
		ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
		ret.put(KEY_RESULT_MSG, "所有的customer以及user");
		ret.put(KEY_RESULT_DATA, service.findAll(userType));
		return ret.toJSONString();
	}
	
}