/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.stocks.controller;
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.Shelves;
import com.tofly.stocks.service.ShelvesService;
import lombok.AllArgsConstructor;
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 java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
 * 库存货架表
 *
 * @author admin
 * @date Fri Nov 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/shelves")
@Api(tags="库存货架表接口")
public class ShelvesController {

    private final  ShelvesService shelvesService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param storeId 库存货架表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询 传参 1、waterworksId 水厂ID ,2 storeName 仓库名称（模糊查询）,3 storeId 仓库Id,4,shelvesNo 货架编码（模糊查询）")
    public ResultRespone getShelvesPage(Page page, 
    		@RequestParam(value = "waterworksId",required = false) String waterworksId,
    		@RequestParam(value = "storeName",required = false) String storeName,
     		@RequestParam(value = "storeId",required = false) String storeId,
            @RequestParam(value = "shelvesNo",required = false) String shelvesNo
    		) {
    	
    	Map<String,Object> queryMaps =new HashMap<String,Object>();
    	queryMaps.put("waterworksId", waterworksId);
    	queryMaps.put("storeName", storeName);
    	queryMaps.put("storeId", storeId);
        queryMaps.put("shelvesNo", shelvesNo);

    	return ResultRespone.success(shelvesService.getShelvesPage(page, queryMaps));
    }

    
    
    /**
     * 货架List查询
     * @param waterworksId
     * @param storeId 库存货架表
     * @return
     */
     @GetMapping("/list" )
     @ApiOperation(value = "分页查询 传参 1、waterworksId 水厂ID ,2 storeName 仓库名称（模糊查询）,3 storeId 仓库Id,4,shelvesNo 货架编码（模糊查询）")
     public ResultRespone getShelvesList(
             @RequestParam(value = "waterworksId",required = false) String waterworksId,
             @RequestParam(value = "storeName",required = false) String storeName,
             @RequestParam(value = "storeId",required = false) String storeId,
             @RequestParam(value = "shelvesNo",required = false) String shelvesNo
     ) {

         Map<String,Object> queryMaps =new HashMap<String,Object>();
         queryMaps.put("waterworksId", waterworksId);
         queryMaps.put("storeName", storeName);
         queryMaps.put("storeId", storeId);
         queryMaps.put("shelvesNo", shelvesNo);
    	 return ResultRespone.success(shelvesService.getShelves(queryMaps));
     }


    /**
     * 通过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(shelvesService.getById(id));
    }

    /**
     * 新增库存货架表
     * @param shelves 库存货架表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增库存货架表" )
    @ApiOperation(value = "新增库存货架表")
    @PostMapping
    public ResultRespone save(@RequestBody Shelves shelves) {
        if(shelvesService.isExist(shelves)){
            return ResultRespone.failed("对应仓库下货架编号已经存在，不能新增");
        }
      return ResultRespone.success(shelvesService.save(shelves));
    }

    /**
     * 修改库存货架表
     * @param shelves 库存货架表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改库存货架表" )
    @ApiOperation(value = "修改库存货架表")
    @PutMapping
    public ResultRespone updateById(@RequestBody Shelves shelves) {
        if(shelvesService.isExist(shelves)){
            return ResultRespone.failed("对应仓库下货架编号已经存在，不能修改");
        }
      return ResultRespone.success(shelvesService.updateById(shelves));
    }

    /**
     * 通过id删除库存货架表
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除库存货架表" )
    @ApiOperation(value = "通过ID删除库存货架表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(shelvesService.removeById(id));
    }

    /**
     * 通过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(shelvesService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
