package com.kmall.admin.controller.mk.store;

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

import com.kmall.admin.entity.mk.store.MkStorePromTypeEntity;
import com.kmall.admin.service.mk.store.MkStorePromTypeService;
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.*;

/**
 * 门店活动分类表，store promotionController
 *
 * @author emato
 * @email admin@qhdswl.com
 * @date 2019-04-28 14:15:21
 */
@Controller
@RequestMapping("mkstorepromtype")
public class MkStorePromTypeController {
    @Autowired
    private MkStorePromTypeService mkStorePromTypeService;

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

        List<MkStorePromTypeEntity> mkStorePromTypeList = mkStorePromTypeService.queryList(query);
        int total = mkStorePromTypeService.queryTotal(query);

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

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

    /**
     * 查看信息
     */
    @RequestMapping("/info/{promTypeId}")
    @RequiresPermissions("mkstorepromtype:info")
    @ResponseBody
    public R info(@PathVariable("promTypeId") Integer promTypeId) {
        MkStorePromTypeEntity mkStorePromType = mkStorePromTypeService.queryObject(promTypeId);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("mkstorepromtype:save")
    @ResponseBody
    public R save(@RequestBody MkStorePromTypeEntity mkStorePromType) {
        mkStorePromTypeService.save(mkStorePromType);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("mkstorepromtype:update")
    @ResponseBody
    public R update(@RequestBody MkStorePromTypeEntity mkStorePromType) {
        mkStorePromTypeService.update(mkStorePromType);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("mkstorepromtype:delete")
    @ResponseBody
    public R delete(@RequestBody Integer[]promTypeIds) {
        mkStorePromTypeService.deleteBatch(promTypeIds);

        return R.ok();
    }

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

        List<MkStorePromTypeEntity> list = mkStorePromTypeService.queryList(params);

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