package com.younike.store.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.dto.AjaxResult;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.BaseAllocation;
import com.younike.service.service.IBaseAllocationService;
import com.younike.common.core.page.TableResult;

/**
 * 门店基础配置Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/baseAllocation")
public class BaseAllocationController extends BaseController {
    @Autowired
    private IBaseAllocationService baseAllocationService;

    /**
     * 查询门店基础配置列表
     */
    @RequiresPermissions("allocation:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<BaseAllocation> page) {

        return baseAllocationService.page(page);
    }


    /**
     * 获取门店基础配置详细信息
     */
    @RequiresPermissions("allocation:query")
    @GetMapping(value = "/{baseAllocationId}")
    public APIResult getInfo(@PathVariable("baseAllocationId") String baseAllocationId) {
        return ResultGenerator.getSuccessResult(baseAllocationService.getById(baseAllocationId));
    }

    /**
     * 新增门店基础配置
     */
    @RequiresPermissions("allocation:add")
    @OpLog(title = "门店基础配置", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody BaseAllocation baseAllocation) {
        return ResultGenerator.getSuccessResult(baseAllocationService.save(baseAllocation));
    }

    /**
     * 修改门店基础配置
     */
    @RequiresPermissions("allocation:edit")
    @OpLog(title = "门店基础配置", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody BaseAllocation baseAllocation) {
        return ResultGenerator.getSuccessResult(baseAllocationService.updateById(baseAllocation));
    }

    /**
     * 删除门店基础配置
     */
    @RequiresPermissions("allocation:remove")
    @OpLog(title = "门店基础配置", type = BusinessType.DELETE)
    @DeleteMapping("/{baseAllocationIds}")
    public APIResult remove(@PathVariable List<String> baseAllocationIds) {
        return ResultGenerator.getSuccessResult(baseAllocationService.removeByIds(baseAllocationIds));
    }
}
