package com.jeeplus.psimanage.materialType.controller;

import com.jeeplus.psimanage.materialType.domain.PsiMaterialTypeInfo;
import com.jeeplus.psimanage.materialType.mapper.PsiMaterialTypeMapper;
import com.jeeplus.psimanage.materialType.service.PsiMaterialTypeForTreeDataService;
import com.jeeplus.psimanage.materialType.service.PsiMaterialTypeService;
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;

/**
 * @author: 王强
 * @create: 2022-11-25 09:18
 **/
@RestController
@Api(tags ="财务-报销类型管理")
@RequestMapping(value = "/psi/materialType")
public class PsiMaterialTypeController {

    @Resource
    private PsiMaterialTypeService service;

    @Resource
    private PsiMaterialTypeForTreeDataService treeService;

    @Resource
    private PsiMaterialTypeMapper mapper;

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

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

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

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

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

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

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

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

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

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

}
