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

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

import com.kmall.admin.entity.OrderEntity;
import com.kmall.admin.entity.mk.store.MkStoreTopicStatEntity;
import com.kmall.admin.service.OrderService;
import com.kmall.admin.service.mk.store.MkStoreTopicStatService;
import com.kmall.admin.utils.ParamUtils;
import com.kmall.common.utils.MapUtils;
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-24 17:58:24
 */
@Controller
@RequestMapping("mkstoretopicstat")
public class MkStoreTopicStatController {
    @Autowired
    private MkStoreTopicStatService mkStoreTopicStatService;
    @Autowired
    private OrderService orderService;

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

        List<MkStoreTopicStatEntity> mkStoreTopicStatList = mkStoreTopicStatService.queryList(query);
        int total = mkStoreTopicStatService.queryTotal(query);

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

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

    /**
     * 查看信息
     */
    @RequestMapping("/info/{storeTopicStatId}")
    @RequiresPermissions("mkstoretopicstat:info")
    @ResponseBody
    public R info(@PathVariable("storeTopicStatId") Integer storeTopicStatId) {
        MkStoreTopicStatEntity mkStoreTopicStat = mkStoreTopicStatService.queryObject(storeTopicStatId);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("mkstoretopicstat:save")
    @ResponseBody
    public R save(@RequestBody MkStoreTopicStatEntity mkStoreTopicStat) {
        mkStoreTopicStatService.save(mkStoreTopicStat);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("mkstoretopicstat:update")
    @ResponseBody
    public R update(@RequestBody MkStoreTopicStatEntity mkStoreTopicStat) {
        mkStoreTopicStatService.update(mkStoreTopicStat);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("mkstoretopicstat:delete")
    @ResponseBody
    public R delete(@RequestBody Integer[]storeTopicStatIds) {
        mkStoreTopicStatService.deleteBatch(storeTopicStatIds);

        return R.ok();
    }

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

        List<MkStoreTopicStatEntity> list = mkStoreTopicStatService.queryList(params);

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

    @RequestMapping("/storeTopicOrderList")
//    @RequiresPermissions("mkstoretopicstat:storeTopicOrderList")
    @ResponseBody
    public R storeTopicOrderList(@RequestParam Map<String, Object> params) {
        ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");
        //查询列表数据
        Query query = new Query(params);
        List<OrderEntity> mkStorePromStatList = orderService.storeTopicOrderList(query);
        int total = orderService.queryStoreTopicOrderTotal(query);

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

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