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

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

import com.kmall.admin.entity.mk.store.MkStoreCampMinusGoodsEntity;
import com.kmall.admin.service.mk.store.MkStoreCampMinusGoodsService;
import com.kmall.admin.utils.ParamUtils;
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 2019-05-29 14:43:29
 */
@Controller
@RequestMapping("mkstorecampminusgoods")
public class MkStoreCampMinusGoodsController {
    @Autowired
    private MkStoreCampMinusGoodsService mkStoreCampMinusGoodsService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("mkstorecampminusgoods:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<MkStoreCampMinusGoodsEntity> mkStoreCampMinusGoodsList = mkStoreCampMinusGoodsService.queryList(query);
        int total = mkStoreCampMinusGoodsService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(mkStoreCampMinusGoodsList, total, query.getLimit(), query.getPage());

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

    @RequestMapping("/queryCampMinusGoodsByIdList")
    @ResponseBody
    public R queryCampMinusGoodsByIdList(@RequestParam Map<String, Object> params) {
        //查询列表数据
        ParamUtils.setName(params, "goodsName");
        Query query = new Query(params);
        List<MkStoreCampMinusGoodsEntity> mkStoreCampMinusGoodsList = mkStoreCampMinusGoodsService.queryCampMinusGoodsByIdList(query);
        int total = mkStoreCampMinusGoodsService.queryCampMinusGoodsByIdTotal(query);
        PageUtils pageUtil = new PageUtils(mkStoreCampMinusGoodsList, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{minusGoodId}")
    @RequiresPermissions("mkstorecampminusgoods:info")
    @ResponseBody
    public R info(@PathVariable("minusGoodId") Integer minusGoodId) {
        MkStoreCampMinusGoodsEntity mkStoreCampMinusGoods = mkStoreCampMinusGoodsService.queryObject(minusGoodId);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("mkstorecampminusgoods:save")
    @ResponseBody
    public R save(@RequestBody MkStoreCampMinusGoodsEntity mkStoreCampMinusGoods) {
        mkStoreCampMinusGoodsService.save(mkStoreCampMinusGoods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("mkstorecampminusgoods:update")
    @ResponseBody
    public R update(@RequestBody MkStoreCampMinusGoodsEntity mkStoreCampMinusGoods) {
        mkStoreCampMinusGoodsService.update(mkStoreCampMinusGoods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("mkstorecampminusgoods:delete")
    @ResponseBody
    public R delete(@RequestBody Integer[]minusGoodIds) {
        mkStoreCampMinusGoodsService.deleteBatch(minusGoodIds);

        return R.ok();
    }

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

        List<MkStoreCampMinusGoodsEntity> list = mkStoreCampMinusGoodsService.queryList(params);

        return R.ok().put("list", list);
    }
    /**
     * 保存
     */
    @RequestMapping("/batchSaveCampMinusGoods")
//    @RequiresPermissions("mkstorecampminusgoods:save")
    @ResponseBody
    public R batchSaveCampMinusGoods(@RequestBody MkStoreCampMinusGoodsEntity mkStoreCampMinusGoods) {
        mkStoreCampMinusGoodsService.batchSaveCampMinusGoods(mkStoreCampMinusGoods);

        return R.ok();
    }
}
