/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.stocks.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.stocks.entity.Store;
import com.tofly.stocks.service.StoreService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;
import java.util.List;
/**
 * 库存仓库表
 *
 * @author admin
 * @date Fri Nov 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/store")
@Api(tags="库存仓库表接口")
public class StoreController {

    private final  StoreService storeService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param store 库存仓库表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getStorePage(Page page, @ModelAttribute Store store) {
      return ResultRespone.success(storeService.page(page, Wrappers.query(store)));
    }


    /**
     * 通过id查询库存仓库表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(storeService.getById(id));
    }

    /**
     * 新增库存仓库表
     * @param store 库存仓库表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增库存仓库表" )
    @ApiOperation(value = "新增库存仓库表")
    @PostMapping
    public ResultRespone save(@RequestBody @Validated Store store) {
      return ResultRespone.success(storeService.saveStore(store));
    }

    /**
     * 修改库存仓库表
     * @param store 库存仓库表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改库存仓库表" )
    @ApiOperation(value = "修改库存仓库表")
    @PutMapping
    public ResultRespone updateById(@RequestBody @Validated Store store) {
      return ResultRespone.success(storeService.editStore(store));
    }


    /**
     * 通过id批量删除库存仓库表
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id批量删除库存仓库表" )
    @ApiOperation(value = "通过ID批量删除库存仓库表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(storeService.deleteByIds(ids));
    }
    
    
    
    /**
     * 通过水厂id查询仓库列表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/getStoresByWaterworksId/{id}" )
    @ApiOperation(value = "通过水厂id查询仓库列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getStoresByWaterworksId(@PathVariable("id" ) Long id) {    	    	
    	List<Store> storeList = storeService.list(Wrappers.<Store>lambdaQuery()
    			.like(Store::getWaterworksId, id).eq(Store::getStoreEnable,"1"));
    	return ResultRespone.success(storeList);
    }
    
    
}
