package com.pj.project.re_role_menu;

import java.util.List;

import com.pj.project.re_role_menu.dto.AssignPermissionsDto;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.pj.utils.sg.*;
import com.pj.project4sp.SP;


/**
 * Controller: re_role_menu -- app用户菜单中间表
 * @author qzy 
 */
@RestController
@RequestMapping("/app/ReRoleMenu/")
public class AppRoleMenuController {

	/** 底层 Service 对象 */
	@Autowired
	ReRoleMenuService reRoleMenuService;

	/** 增 */  
	@RequestMapping("add")
//	@SaCheckPermission(ReRoleMenu.PERMISSION_CODE_ADD)
	public AjaxJson add(ReRoleMenu r){
		reRoleMenuService.add(r);
		r = reRoleMenuService.getById(SP.publicMapper.getPrimarykey());
		return AjaxJson.getSuccessData(r);
	}

	/** 删 */  
	@RequestMapping("delete")
//	@SaCheckPermission(ReRoleMenu.PERMISSION_CODE_DEL)
	public AjaxJson delete(Long id){
		 reRoleMenuService.delete(id);
		return AjaxJson.getSuccess();
	}
	
	/** 删 - 根据id列表 */  
	@RequestMapping("deleteByIds")
//	@SaCheckPermission(ReRoleMenu.PERMISSION_CODE_DEL)
	public AjaxJson deleteByIds(){
		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); 
		int line = SP.publicMapper.deleteByIds(ReRoleMenu.TABLE_NAME, ids);
		return AjaxJson.getByLine(line);
	}
	
	/** 改 */  
	@RequestMapping("update")
//	@SaCheckPermission(ReRoleMenu.PERMISSION_CODE_EDIT)
	public AjaxJson update(ReRoleMenu r){
		reRoleMenuService.update(r);
		return AjaxJson.getSuccess();
	}

	/** 查 - 根据id */  
	@RequestMapping("getById")
//		@SaCheckPermission(ReRoleMenu.PERMISSION_CODE)
	public AjaxJson getById(Long id){
		ReRoleMenu r = reRoleMenuService.getById(id);
		return AjaxJson.getSuccessData(r);
	}

	/**
	 * 查集合 - 根据条件（参数为空时代表忽略指定条件）
	 * @param appRoleId 职务ID,非必填
	 * @return
	 */
	@RequestMapping("getList")
//		@SaCheckPermission(ReRoleMenu.PERMISSION_CODE)
	public AjaxJson getList(@RequestParam(value = "appRoleId",required = false) Integer appRoleId) {
		SoMap so = SoMap.getRequestSoMap();
		List<ReRoleMenu> list = reRoleMenuService.getList(so.startPage(),appRoleId);
		return AjaxJson.getPageData(so.getDataCount(), list);
	}



	
	

	
	
	

}
