package io.renren.modules.admin.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.admin.entity.PaperRequireEntity;
import io.renren.modules.admin.service.PaperRequireService;



/**
 * 投稿要求表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-03-16 11:02:40
 */
@RestController
@RequestMapping("admin/paperrequire")
public class PaperRequireController {
    @Autowired
    private PaperRequireService paperRequireService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("admin:paperrequire:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = paperRequireService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("admin:paperrequire:info")
    public R info(@PathVariable("id") Long id){
		PaperRequireEntity paperRequire = paperRequireService.getById(id);

        return R.ok().put("paperRequire", paperRequire);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("admin:paperrequire:save")
    public R save(@RequestBody PaperRequireEntity paperRequire){
        paperRequire.setCreateTime(new Date());
		paperRequireService.save(paperRequire);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("admin:paperrequire:update")
    public R update(@RequestBody PaperRequireEntity paperRequire){
		paperRequireService.updateById(paperRequire);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresPermissions("admin:paperrequire:delete")
    public R delete(@RequestBody Long[] ids){
		paperRequireService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
