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

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

import com.kmall.admin.entity.mk.store.StoreTopicEntity;
import com.kmall.admin.service.mk.store.StoreTopicService;
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 huangyq
 * @email admin@qhdswl.com
 * @date 2019-04-26 16:50:46
 */
@Controller
@RequestMapping("storetopic")
public class StoreTopicController {
    @Autowired
    private StoreTopicService storeTopicService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("storetopic:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");
        ParamUtils.setName(params, "name");
        //查询列表数据
        Query query = new Query(params);

        List<StoreTopicEntity> storeTopicList = storeTopicService.queryList(query);
        int total = storeTopicService.queryTotal(query);

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

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

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("storetopic:info")
    @ResponseBody
    public R info(@PathVariable("id") Integer id) {
        StoreTopicEntity storeTopic = storeTopicService.queryObject(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("storetopic:save")
    @ResponseBody
    public R save(@RequestBody StoreTopicEntity storeTopic) {
        storeTopicService.save(storeTopic);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("storetopic:update")
    @ResponseBody
    public R update(@RequestBody StoreTopicEntity storeTopic) {
        storeTopicService.update(storeTopic);

        return R.ok();
    }

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

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {
        ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");

        List<StoreTopicEntity> list = storeTopicService.queryList(params);

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