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.PaperEntity;
import io.renren.modules.admin.service.PaperService;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-02-12 10:52:23
 */
@RestController
@RequestMapping("admin/paper")
public class PaperController {
    @Autowired
    private PaperService paperService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("admin:paper:list")
    public R list(@RequestParam Map<String, Object> params){
        if (!params.containsKey("meetingId")) {
            return R.error("会议id不可为空");
        }
        PageUtils page = paperService.myQueryPage(params);

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


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("admin:paper:info")
    public R info(@PathVariable("id") Long id){
		PaperEntity paper = paperService.getById(id);

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

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("admin:paper:save")
    public R save(@RequestBody PaperEntity paper){
        paper.setCreateTime(new Date());
		paperService.save(paper);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("admin:paper:update")
    public R update(@RequestBody PaperEntity paper){
		paperService.updateById(paper);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("admin:paper:delete")
    public R delete(@RequestBody Long[] ids){
		paperService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
