package com.jeeplus.test.reimbursement.reimbursementType.controller;

import com.jeeplus.test.reimbursement.reimbursementType.domain.ReimbursementTypeInfo;
import com.jeeplus.test.reimbursement.reimbursementType.mapper.ReimbursementTypeMapper;
import com.jeeplus.test.reimbursement.reimbursementType.service.ReimbursementTypeForTreeDataService;
import com.jeeplus.test.reimbursement.reimbursementType.service.ReimbursementTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags ="报销类型管理")
@RequestMapping(value = "/reimbursement/type")
public class ReimbursementTypeController {

    @Resource
    private ReimbursementTypeService service;

    @Resource
    private ReimbursementTypeForTreeDataService treeService;

    @Resource
    private ReimbursementTypeMapper mapper;

    /**
     * 列表查询
     * @param info
     * @return
     */
    @ApiOperation(value = "列表查询")
    @GetMapping("/list")
    public ResponseEntity<List<ReimbursementTypeInfo>> list(ReimbursementTypeInfo info) {
        List<ReimbursementTypeInfo> list = service.list(info);
        return ResponseEntity.ok(list);
    }

    /**
     * 新增/修改
     * @param info
     * @return
     */
    @ApiOperation(value = "新增/修改")
    @PostMapping("/save")
    public ResponseEntity<String> save(@RequestBody ReimbursementTypeInfo info) {
        String s = service.save(info);
        return ResponseEntity.ok(s);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping("/findById")
    public ResponseEntity<ReimbursementTypeInfo> findById(String id) {
        ReimbursementTypeInfo info = mapper.selectById(id);
        return ResponseEntity.ok(info);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id删除")
    @GetMapping("/deleteById")
    public ResponseEntity<String> deleteById(String id) {
        mapper.deleteById(id);
        return ResponseEntity.ok("操作完成");
    }

    /**
     * 查询树形
     * @param extId 排除的ID
     * @return
     */
    @ApiOperation(value = "查询树形")
    @GetMapping("/treeData")
    public ResponseEntity<List<ReimbursementTypeInfo>> treeData(@RequestParam(required = false) String extId, @RequestParam(required = false) String type) throws Exception{
        List<ReimbursementTypeInfo> infos = treeService.treeDataForType(extId, type);
        return ResponseEntity.ok(infos);
    }

}
