package jj.tech.paolu.repository.mybatis.control;

import jj.tech.paolu.repository.mybatis.dao.SysRoleResourceMapper;
import jj.tech.paolu.repository.mybatis.entity.SysRoleResource;
import jj.tech.paolu.utils.IDHelp;
import jj.tech.paolu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("mybatis/sysRoleResource")
public class SysRoleResourceController {

    @Autowired
    public SysRoleResourceMapper sysRoleResourceMapper;

    @PostMapping("findById/{roleid}/{resid}")
    public Object findById(@PathVariable("roleid") String roleid, @PathVariable("resid") String resid) {
        return R.SUCCESS(sysRoleResourceMapper.selectByPrimaryKey(roleid,resid).orElse(null));
    }

    @PostMapping("delete/{roleid}/{resid}")
    public Object delete(@PathVariable("roleid") String roleid, @PathVariable("resid") String resid) {
        return R.SUCCESS(sysRoleResourceMapper.deleteByPrimaryKey(roleid,resid));
    }

    @PostMapping("save")
    public Object save(@RequestBody SysRoleResource record) {
        record.setId(IDHelp.getInstance().nextId());
        return R.SUCCESS(sysRoleResourceMapper.insertSelective(record));
    }

    @PostMapping("update")
    public Object update(@RequestBody SysRoleResource record) {
        return R.SUCCESS(sysRoleResourceMapper.updateByPrimaryKeySelective(record));
    }
}