package com.kmall.admin.controller;

import java.util.List;
import java.util.Map;

import com.kmall.admin.entity.FreightItemEntity;
import com.kmall.admin.service.FreightItemService;
import com.kmall.common.utils.PageUtils;
import com.kmall.common.utils.Query;
import com.kmall.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Controller
 *
 * @author emato
 * @email admin@qhdswl.com
 * @date 2018-10-22 15:18:16
 */
@Controller
@RequestMapping("freightitem")
public class FreightItemController {
    @Autowired
    private FreightItemService freightItemService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("freightitem:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<FreightItemEntity> freightItemList = freightItemService.queryList(query);
        int total = freightItemService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(freightItemList, total, query.getLimit(), query.getPage());

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

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("freightitem:info")
    @ResponseBody
    public R info(@PathVariable("id") Integer id) {
        FreightItemEntity freightItem = freightItemService.queryObject(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("freightitem:save")
    @ResponseBody
    public R save(@RequestBody FreightItemEntity freightItem) {
        freightItemService.save(freightItem);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("freightitem:update")
    @ResponseBody
    public R update(@RequestBody FreightItemEntity freightItem) {
        freightItemService.update(freightItem);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("freightitem:delete")
    @ResponseBody
    public R delete(@RequestBody Integer[]ids) {
        freightItemService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<FreightItemEntity> list = freightItemService.queryList(params);

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