package com.jeeplus.human.practice.reimburseRegister.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.human.practice.reimburseRegister.domain.ReimburseRegister;
import com.jeeplus.human.practice.reimburseRegister.domain.ReimburseSubmitAccount;
import com.jeeplus.human.practice.reimburseRegister.service.ReimburseSubmitAccountService;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author 王强
 * @version 1.0
 * @date 2023-09-22 13:59
 */
@RestController
@Api("实习报销")
@RequestMapping(value = "/reimburseSubmitAccount")
public class ReimburseSubmitAccountController {

    @Resource
    private ReimburseSubmitAccountService accountService;

    /**
     * 查询实习报销信息列表
     * @param projectReportData
     * @param page
     * @return
     */
    @ApiLog("查询实习报销列表")
    @PreAuthorize("hasAuthority('reimburseSubmitAccount:list')")
    @GetMapping("list")
    public ResponseEntity<IPage<ReimburseSubmitAccount>> data(ReimburseSubmitAccount projectReportData, Page<ReimburseSubmitAccount> page) throws Exception {
        IPage<ReimburseSubmitAccount> result = new Page<ReimburseSubmitAccount>();
        result = accountService.findList (page,projectReportData);
        return ResponseEntity.ok (result);
    }

    /**
     * 保存实习人员登记信息
     * @param reimburseRegister
     * @return
     */
    @ApiLog(value = "保存报销登记信息", type = LogTypeEnum.SAVE)
    @PreAuthorize("hasAnyAuthority('reimburseSubmitAccount:add','reimburseSubmitAccount:edit')")
    @PostMapping("save")
    public ResponseEntity save(@Valid @RequestBody ReimburseSubmitAccount reimburseRegister) throws Exception {
        ReimburseSubmitAccount s = accountService.saveSubmitAccount(reimburseRegister);
        return ResponseUtil.newInstance().add("businessTable", "human_resources_practice_reimburse_submit_account")
                .add("businessId", s.getId())
                .ok ("操作成功");
    }

    /**
     * 查询
     * @param id
     * @return
     */
    @ApiOperation(value = "查询")
    @GetMapping("/findById")
    public ResponseEntity<ReimburseSubmitAccount> findById(@RequestParam String id) throws Exception{
        ReimburseSubmitAccount dto = accountService.findById(id);
        return ResponseEntity.ok(dto);
    }

    /**
     * 根据id修改状态status
     */
    @ApiOperation(value = "根据id修改状态status")
    @PostMapping(value = "updateStatusById")
    public void updateStatusById(@RequestBody ReimburseSubmitAccount dto) {
        accountService.updateStatusById(dto);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation(value = "删除")
    @GetMapping("/remove")
    public ResponseEntity<String> remove(@RequestParam String id){
        String s = accountService.remove(id);
        return ResponseEntity.ok(s);
    }

}
