package com.mortals.xhx.base.system.role.web;


import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色资源权限
 *
 * @author: zxfei
 * @date: 2022/5/7 15:19
 */
@Slf4j
@RestController
@RequestMapping("role/auth")
public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAuthService, RoleAuthEntity, Long> {

    public RoleAuthController() {
        super.setModuleDesc("角色资源权限");
    }

    /**
     * 分配资源
     */
    @PostMapping(value = "distributionSource")
    public String distributionUser(@RequestBody RoleAuthQuery query) {
        try {
            service.doDistributionSource(query);
            JSONObject ret = new JSONObject();
            ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
            return ret.toJSONString();
        } catch (Exception e) {
            log.error("分配角色资源错误", e);
            JSONObject ret = new JSONObject();
            ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
            ret.put(KEY_RESULT_MSG, super.convertException(e));
            return ret.toJSONString();
        }
    }

}