/*
 * 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.dto.CheckPlanQuery;
import com.tofly.stocks.entity.CheckPlan;
import com.tofly.stocks.service.CheckPlanService;
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;

/**
 * 库存盘点计划表
 *
 * @author admin
 * @date Fri Nov 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/checkplan")
@Api(tags="库存盘点计划表接口")
public class CheckPlanController {

    private final  CheckPlanService checkPlanService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param CheckPlanQuery 库存盘点计划表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getCheckPlanPage(Page page, @Validated CheckPlanQuery CheckPlanQuery) {
    	return ResultRespone.success(checkPlanService.getDataPage(page, CheckPlanQuery));
    }


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

    /**
     * 新增库存盘点计划表
     * @param checkPlan 库存盘点计划表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增库存盘点计划表" )
    @ApiOperation(value = "新增库存盘点计划表")
    @PostMapping
    public ResultRespone save(@RequestBody CheckPlan checkPlan) {    	
    	try {
    		checkPlanService.saveCheckPlan(checkPlan);
    		return ResultRespone.success("盘点计划添加成功。");
    	}catch (Exception e) {
    		return ResultRespone.failed(e.getMessage());
		}    	   	    	    	
    }

    /**
     * 修改库存盘点计划表
     * @param checkPlan 库存盘点计划表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改库存盘点计划表" )
    @ApiOperation(value = "修改库存盘点计划表")
    @PutMapping
    public ResultRespone updateById(@RequestBody CheckPlan checkPlan) {
      return ResultRespone.success(checkPlanService.editCheckPlan(checkPlan));
    }

    /**
     * 通过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(checkPlanService.deleteByIds(ids));
    }
}
