package io.renren.modules.admin.controller;

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

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

import io.renren.modules.admin.entity.MaterialStorageEntity;
import io.renren.modules.admin.service.MaterialStorageService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.UpdateGroup;



/**
 * 材料保管使用技术条件
 *
 * @author huwhois
 * @email huwhois@gmail.com
 * @date 2020-08-03 13:36:30
 */
@RestController
@RequestMapping("admin/materialstorage")
public class MaterialStorageController {
    @Autowired
    private MaterialStorageService materialStorageService;

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

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

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("admin:materialstorage:info")
    public R info(@PathVariable("id") Long id){
		MaterialStorageEntity materialStorage = materialStorageService.getById(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("admin:materialstorage:save")
    public R save(@RequestBody MaterialStorageEntity materialStorage){
        ValidatorUtils.validateEntity(materialStorage, AddGroup.class);
		materialStorageService.save(materialStorage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("admin:materialstorage:update")
    public R update(@RequestBody MaterialStorageEntity materialStorage){
        ValidatorUtils.validateEntity(materialStorage, UpdateGroup.class);
		materialStorageService.updateById(materialStorage);

        return R.ok();
    }

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

        return R.ok();
    }

}
