/*
 * 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.CheckTaskInfoDto;
import com.tofly.stocks.dto.CheckTaskQuery;
import com.tofly.stocks.service.CheckTaskService;
import com.tofly.stocks.vo.CheckTaskVo;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import java.util.Arrays;
import java.util.List;
/**
 * 库存盘点任务表
 *
 * @author admin
 * @date Fri Nov 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/checktask")
@Api(tags="库存盘点任务表接口")
public class CheckTaskController {

    private final  CheckTaskService checkTaskService;
    
    

    /**
    * 分页查询
    * @param page 分页对象
    * @param checkTaskQuery 库存盘点任务表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getCheckTaskPage(Page page, @Validated CheckTaskQuery checkTaskQuery) {
    	Page<CheckTaskVo>  list = checkTaskService.getDataPage(page, checkTaskQuery);
    	return ResultRespone.success(list);
    }


    /**
     * 通过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(checkTaskService.getById(id));
    }
    
    
    
    /**
     * 通过盘点任务id查询盘点任务明细
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/checkDetails/{id}" )
    @ApiOperation(value = "通过盘点任务id查询盘点任务明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getCheckDetailsByTaskId(@PathVariable("id" ) Long id) {
    	return ResultRespone.success(checkTaskService.getCheckDetailsByTaskId(id));
    }

    /**
     * 修改库存盘点任务
     * @param checkTaskInfoDto 库存盘点任务
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改库存盘点任务表" )
    @ApiOperation(value = "修改库存盘点任务表")
    @PutMapping
    public ResultRespone updateById(@Validated CheckTaskInfoDto checkTaskInfoDto,
    		 @RequestPart(required = false) @ApiParam("附件列表") List<MultipartFile> files) { 	
    	try {
    		checkTaskService.editCheckTaskInfo(checkTaskInfoDto,files);
    		return ResultRespone.success("修改库存盘点任务成功");
    	}catch (Exception e) {
			e.printStackTrace();
			return ResultRespone.failed(e.getMessage());
		}
    }


}
