package com.prolog.rdc.tms.controller;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.product.core.easyexcel.util.ExcelUtils;
import com.prolog.rdc.tms.model.dto.BmsSettlementFeeDTO;
import com.prolog.rdc.tms.model.entity.BmsSettlementFeeModel;
import com.prolog.rdc.tms.model.vo.BmsSettlementFeeQueryVO;
import com.prolog.rdc.tms.model.vo.BmsSettlementFeeVO;
import com.prolog.rdc.tms.model.vo.SettlementFeeImportVO;
import com.prolog.rdc.tms.model.vo.StatusUpdate;
import com.prolog.rdc.tms.service.SettlementFeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "费用管理-结算费用")
@RestController
@RequestMapping("/settlementFee")
public class SettlementFeeController {

    @Autowired
    private SettlementFeeService settlementFeeService;

    @UserLog("结算费用分页查询")
    @ApiOperation(value = "结算费用分页查询", notes = "结算费用分页查询")
    @PostMapping("/findList")
    public RestMessage<Page<BmsSettlementFeeDTO>> findList(@RequestBody BmsSettlementFeeQueryVO vo) throws Exception {
        Page<BmsSettlementFeeDTO> list = settlementFeeService.findList(vo);
        return RestMessage.newInstance(true, "操作成功", list);
    }

    @UserLog("结算费用不分页")
    @ApiOperation(value = "结算费用不分页", notes = "结算费用不分页")
    @PostMapping("/findListNoPage")
    public RestMessage<List<BmsSettlementFeeDTO>> findListNoPage(@RequestParam(value = "code") String code) {
        List<BmsSettlementFeeDTO> list = settlementFeeService.findListNoPage(code);
        return RestMessage.newInstance(true, "操作成功", list);
    }

    @UserLog("结算费用新增")
    @ApiOperation(value = "结算费用新增", notes = "结算费用新增")
    @PostMapping("/save")
    public RestMessage<Object> save(@RequestBody BmsSettlementFeeVO vo) throws Exception {
        settlementFeeService.save(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("结算费用查询详情")
    @ApiOperation(value = "结算费用查询详情", notes = "结算费用查询详情")
    @PostMapping("/detail")
    public RestMessage<BmsSettlementFeeDTO> detail(@RequestParam(value = "id") Long id) throws Exception {
        BmsSettlementFeeDTO dto =  settlementFeeService.detail(id);
        return RestMessage.newInstance(true, "操作成功", dto);
    }

    @UserLog("结算费用修改")
    @ApiOperation(value = "结算费用修改", notes = "结算费用修改")
    @PostMapping("/update")
    public RestMessage<Object> update(@RequestBody BmsSettlementFeeVO vo) throws Exception {
        settlementFeeService.update(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("结算费状态修改")
    @ApiOperation(value = "结算费状态修改", notes = "结算费状态修改")
    @PostMapping("/updateStatus")
    public RestMessage<Object> updateStatus(@RequestBody List<StatusUpdate> vo) throws Exception {
        settlementFeeService.updateStatus(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("结算费用删除")
    @ApiOperation(value = "结算费用删除", notes = "结算费用删除")
    @PostMapping("/delete")
    public RestMessage<Object> delete(@RequestBody String[] ids) {
        settlementFeeService.delete(ids);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("导入")
    @ApiOperation(value = "导入", notes = "导入")
    @PostMapping("/importExpense")
    public RestMessage<Object> importExpense(@RequestParam("file") MultipartFile file) throws IOException {
        settlementFeeService.importExpense(file);
        return RestMessage.newInstance(true, "导入成功", null);
    }

    @UserLog("模版下载")
    @ApiOperation(value = "模版下载", notes = "模版下载")
    @PostMapping("/downloadTemplate")
    public RestMessage<Object> downloadTemplate(HttpServletResponse response) throws IOException {
        List<SettlementFeeImportVO> list = new ArrayList<>();
        ExcelUtils.export(response, SettlementFeeImportVO.class,  "结算费用", list,null,null,true);
        return null;
    }
}