/*
 * 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.DrugUseInfoDto;
import com.tofly.stocks.dto.DrugUseInfoQuery;
import com.tofly.stocks.dto.DrugUseReportQuery;
import com.tofly.stocks.service.DrugUseInfoService;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * 药品使用信息表
 *
 * @author admin
 * @date Fri Nov 25 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/druguseinfo")
@Api(tags="药品使用信息表接口")
public class DrugUseInfoController {

    private final  DrugUseInfoService drugUseInfoService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param drugUseInfoQuery 药品使用信息表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getDrugUseInfoPage(Page page, @ModelAttribute DrugUseInfoQuery drugUseInfoQuery) {
      return ResultRespone.success(drugUseInfoService.getDataPage(page, drugUseInfoQuery));
    }


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

    /**
     * 新增药品使用信息表
     * @param drugUseInfoDto 药品使用信息表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增药品使用信息表" )
    @ApiOperation(value = "新增药品使用信息表")
    @PostMapping
    public ResultRespone save(@Validated DrugUseInfoDto drugUseInfoDto,
                              @RequestPart(required = false) @ApiParam("附件列表") List<MultipartFile> files) {
      return ResultRespone.success(drugUseInfoService.saveDrugUseInfo(drugUseInfoDto,files));
    }

    /**
     * 修改药品使用信息表
     * @param drugUseInfoDto 药品使用信息表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改药品使用信息表" )
    @ApiOperation(value = "修改药品使用信息表")
    @PutMapping
    public ResultRespone updateById(@Validated DrugUseInfoDto drugUseInfoDto,
                                    @RequestPart(required = false) @ApiParam("附件列表") List<MultipartFile> files) {
      return ResultRespone.success(drugUseInfoService.editDrugUseInfo(drugUseInfoDto,files));
    }


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



    /**
     * 报表查询
     * @param drugUseReportQuery 药耗统计
     * @return
     */

    @ToFlyAppLog(title = "药耗分析-列表")
    @ApiOperation(value = "药耗分析-列表")
    @GetMapping("/report" )

    public ResultRespone getDrugReportPage(Page page,@Validated DrugUseReportQuery drugUseReportQuery) {
        return ResultRespone.success(drugUseInfoService.getReportList(page,drugUseReportQuery));
    }

    /**
     * 数据导出
     *
     * @param drugUseReportQuery 查询模型
     */
    @ToFlyAppLog(title = "药耗分析-数据导出")
    @ApiOperation(value = "药耗分析-数据导出")
    @GetMapping("/export")
    public void export(@Validated DrugUseReportQuery drugUseReportQuery) {

        drugUseInfoService.export(drugUseReportQuery);

}
}
