com.base4j.mvc.sys.controller.SysRoleResourceController Maven / Gradle / Ivy
package com.base4j.mvc.sys.controller;
import com.base4j.mvc.base.controller.BaseController;
import com.base4j.mvc.sys.entity.SysResource;
import com.base4j.mvc.sys.entity.SysRoleResource;
import com.base4j.mvc.sys.service.SysResourceService;
import com.base4j.mvc.sys.service.SysRoleResourceService;
import com.base4j.mvc.util.Res;
import com.base4j.mybatis.base.QueryParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequestMapping("/sys/roleResource")
@RestController
public class SysRoleResourceController extends BaseController {
@Autowired
private SysRoleResourceService sysRoleResourceService;
@Autowired
private SysResourceService sysResourceService;
@RequestMapping("selectResources/{roleId}")
public Res selectResources(@PathVariable("roleId") long roleId) {
return Res.ok(sysRoleResourceService.selectResources(roleId));
}
@RequestMapping("/selectResourceForRole/{roleId}")
public Res selectResourceForRole(@PathVariable long roleId) {
QueryParams queryParams = new QueryParams(SysRoleResource.class);
QueryParams.Criteria criteria = queryParams.createCriteria();
criteria.andEqualTo("sysRoleId", roleId);
List list = sysRoleResourceService.selectListRelativeByParams(queryParams);
return Res.ok(list);
}
@Override
@RequestMapping("/save")
public Res save(@RequestBody SysRoleResource sysRoleResource) {
if (sysRoleResource.getId() == null) {
sysRoleResourceService.insert(sysRoleResource);
} else {
sysRoleResourceService.updateSelectiveByPrimaryKey(sysRoleResource);
}
return Res.ok(sysRoleResource.getId());
}
@RequestMapping("/deleteByPrimary/{id}")
public Res deleteByPrimary(@PathVariable long id) {
sysRoleResourceService.deleteByPrimaryKey(id);
return Res.ok();
}
@RequestMapping("/saveRoleResource")
public Res saveRoleResource(@RequestBody List roleResourceList) {
sysRoleResourceService.saveRoleResources(roleResourceList);
return Res.ok();
}
}