package com.kmall.admin.controller;

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

import com.kmall.admin.entity.MngChangeEntity;
import com.kmall.admin.service.MngChangeService;
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("mngchange")
public class MngChangeController {
    @Autowired
    private MngChangeService mngChangeService;

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

        List<MngChangeEntity> mngChangeList = mngChangeService.queryList(query);
        int total = mngChangeService.queryTotal(query);

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

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

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("mngchange:info")
    @ResponseBody
    public R info(@PathVariable("id") Integer id) {
        MngChangeEntity mngChange = mngChangeService.queryObject(id);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("mngchange:save")
    @ResponseBody
    public R save(@RequestBody MngChangeEntity mngChange) {
        mngChangeService.save(mngChange);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("mngchange:update")
    @ResponseBody
    public R update(@RequestBody MngChangeEntity mngChange) {
        mngChangeService.update(mngChange);

        return R.ok();
    }

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

        return R.ok();
    }

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

        List<MngChangeEntity> list = mngChangeService.queryList(params);

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