package com.kcim.web;

import com.kcim.common.util.PageUtils;
import com.kcim.common.util.Result;
import com.kcim.common.util.UserContext;
import com.kcim.dao.model.CostIncomeFile;
import com.kcim.vo.IncomeErrorMessage;
import com.kcim.service.CostIncomeFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


/**
 * 文件上传记录
 *
 * @author KCYG
 * @date 2021-08-10 14:42:20
 */
@RestController
@RequestMapping("costincomefile")
@Api(tags = "文件记录")
public class CostIncomeFileController {
    @Autowired
    private CostIncomeFileService costIncomeFileService;

    /**
     * 分页查询列表
     * 查询的是
     */
    @GetMapping("/list")
    @ApiOperation("分页查询记录数据")
    public Result list(@RequestParam(value = "current", defaultValue = "1") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                       @RequestParam(value = "fileName",required = false) String fileName,
                       @RequestParam(value = "computeDate",required = false) String computeDate,
                        @RequestParam(required = false)String filter){
        Long hospId = UserContext.getHospId();
        PageUtils pageUtils = costIncomeFileService.queryList(current,pageSize,fileName,computeDate,hospId,filter);
        return Result.ok(pageUtils);
    }

    /**
     * 撤销导入
     * 这个文件的Id
     */
    @PostMapping("/deleteImport")
    @ApiOperation("撤销导入")
    public Result deleteImport(@RequestParam Long id,@RequestParam String computeDate){
        Long hospId = UserContext.getHospId();
        costIncomeFileService.deleteImport(id,hospId,computeDate);
        return Result.ok();
    }
    @PostMapping("/reducingImport")
    @ApiOperation("还原导入")
    public Result reducingImport(@RequestParam Long id,@RequestParam String computeDate){
        Long hospId = UserContext.getHospId();
        costIncomeFileService.reducingImport(id,hospId,computeDate);
        return Result.ok();
    }

    @GetMapping("/getErrorList")
    @ApiOperation("查看错误详情")
    public Result getErrorList(Long id){
        Long hospId = UserContext.getHospId();
        List<IncomeErrorMessage> incomeErrorMessageList = costIncomeFileService.getErrorList(id,hospId);
        return Result.ok(incomeErrorMessageList);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		CostIncomeFile costIncomeFile = costIncomeFileService.getById(id);
        return Result.ok(costIncomeFile);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody CostIncomeFile costIncomeFile){
		costIncomeFileService.save(costIncomeFile);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody CostIncomeFile costIncomeFile){
		costIncomeFileService.updateById(costIncomeFile);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
        costIncomeFileService.deleteByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
