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.service.ReimburseRegisterService;
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-19 13:43
 */
@RestController
@Api("实习报销登记")
@RequestMapping(value = "/reimburseRegister")
public class ReimburseRegisterController {

    @Resource
    private ReimburseRegisterService registerService;

    /**
     * 查询财务项目信息列表
     * @param projectReportData
     * @param page
     * @return
     */
    @ApiLog("查询实习报销登记列表")
    @PreAuthorize("hasAuthority('reimburseRegister:list')")
    @GetMapping("list")
    public ResponseEntity<IPage<ReimburseRegister>> data(ReimburseRegister projectReportData, Page<ReimburseRegister> page) throws Exception {
        IPage<ReimburseRegister> result = new Page<ReimburseRegister>();
        result = registerService.findList (page,projectReportData);
        return ResponseEntity.ok (result);
    }

    /**
     * 查询财务项目信息列表
     * @param projectReportData
     * @param page
     * @return
     */
    @ApiLog("查询实习报销登记列表")
    @GetMapping("list2")
    public ResponseEntity<IPage<ReimburseRegister>> data2(ReimburseRegister projectReportData, Page<ReimburseRegister> page) throws Exception {
        IPage<ReimburseRegister> result = new Page<ReimburseRegister>();
        result = registerService.findList2 (page,projectReportData);
        return ResponseEntity.ok (result);
    }

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

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

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

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