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 com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * 资源信息
 *
 * @author: zxfei
 * @date: 2022/5/7 15:27
 */
@Slf4j
@RestController
@RequestMapping("resource")
public class ResourceController extends BaseCRUDJsonBodyMappingController<ResourceService,ResourceEntity,Long> {

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

	@Override
	protected void init(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);
	}

	/**
	 * 获取所有资源
	 *
	 * @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();
	}
	
}