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

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

import com.kmall.admin.entity.mk.store.MkStorePromChnlEntity;
import com.kmall.admin.service.mk.store.MkStorePromChnlService;
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 15:52:20
 */
@Controller
@RequestMapping("mkstorepromchnl")
public class MkStorePromChnlController {
    @Autowired
    private MkStorePromChnlService mkStorePromChnlService;

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

        List<MkStorePromChnlEntity> mkStorePromChnlList = mkStorePromChnlService.queryList(query);
        int total = mkStorePromChnlService.queryTotal(query);

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

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

    /**
     * 查看信息
     */
    @RequestMapping("/info/{promChnlId}")
    @RequiresPermissions("mkstorepromchnl:info")
    @ResponseBody
    public R info(@PathVariable("promChnlId") Integer promChnlId) {
        MkStorePromChnlEntity mkStorePromChnl = mkStorePromChnlService.queryObject(promChnlId);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("mkstorepromchnl:save")
    @ResponseBody
    public R save(@RequestBody MkStorePromChnlEntity mkStorePromChnl) {
        mkStorePromChnlService.save(mkStorePromChnl);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("mkstorepromchnl:update")
    @ResponseBody
    public R update(@RequestBody MkStorePromChnlEntity mkStorePromChnl) {
        mkStorePromChnlService.update(mkStorePromChnl);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("mkstorepromchnl:delete")
    @ResponseBody
    public R delete(@RequestBody Integer[]promChnlIds) {
        mkStorePromChnlService.deleteBatch(promChnlIds);

        return R.ok();
    }

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

        List<MkStorePromChnlEntity> list = mkStorePromChnlService.queryList(params);

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