package com.kmall.admin.controller;

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

import com.kmall.admin.entity.StoreMngChangeEntity;
import com.kmall.admin.service.StoreMngChangeService;
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-03-11 10:29:49
 */
@Controller
@RequestMapping("storemngchange")
public class StoreMngChangeController {
    @Autowired
    private StoreMngChangeService storeMngChangeService;

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

        List<StoreMngChangeEntity> storeMngChangeList = storeMngChangeService.queryList(query);
        int total = storeMngChangeService.queryTotal(query);

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

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

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("storemngchange:info")
    @ResponseBody
    public R info(@PathVariable("id") Integer id) {
        StoreMngChangeEntity storeMngChange = storeMngChangeService.queryObject(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("storemngchange:save")
    @ResponseBody
    public R save(@RequestBody StoreMngChangeEntity storeMngChange) {
        storeMngChangeService.save(storeMngChange);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("storemngchange:update")
    @ResponseBody
    public R update(@RequestBody StoreMngChangeEntity storeMngChange) {
        storeMngChangeService.update(storeMngChange);

        return R.ok();
    }

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

        return R.ok();
    }

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

        List<StoreMngChangeEntity> list = storeMngChangeService.queryList(params);

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