package com.jeeplus.test.program.configuration.projectDict.controller;

import com.jeeplus.test.program.configuration.fileDict.domain.ProgramFileDict;
import com.jeeplus.test.program.configuration.projectDict.domain.vo.FileDictVo;
import com.jeeplus.test.program.configuration.projectDict.service.ProjectDictService;
import com.jeeplus.test.program.configuration.projectDict.service.dto.ProjectDictDto;
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;

@Api(tags ="项目类型附件设置")
@RestController
@RequestMapping(value = "/program/project")
public class ProjectDictController {

    @Resource
    private ProjectDictService projectDictService;

    /**
     * 查询
     */
    @ApiOperation(value = "查询")
    @PostMapping(value = "/list")
    public ResponseEntity<List<FileDictVo>> list(@RequestBody ProjectDictDto projectDictDto){
        List<FileDictVo> list = projectDictService.list(projectDictDto);
        return ResponseEntity.ok(list);
    }

    /**
     * 新增/修改
     */
    @ApiOperation(value = "新增")
    @PostMapping(value = "/save")
    public ResponseEntity<String> save(@RequestBody ProjectDictDto projectDictDto){
        String add = projectDictService.save(projectDictDto);
        return ResponseEntity.ok(add);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/deleteById")
    public ResponseEntity<String> deleteById(String id){
        String deleteById = projectDictService.deleteById(id);
        return ResponseEntity.ok(deleteById);
    }

    /**
     * 新增下拉查询
     */
    @ApiOperation(value = "新增下拉查询")
    @PostMapping(value = "/getFileList")
    public ResponseEntity<List<ProgramFileDict>> getFileList(@RequestBody ProjectDictDto projectDictDto){
        List<ProgramFileDict> fileList = projectDictService.getFileList(projectDictDto);
        return ResponseEntity.ok(fileList);
    }

    /**
     * 根据id查询
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/findByFileId")
    public ResponseEntity<ProgramFileDict> findByFileId(@RequestParam String id){
        ProgramFileDict fileDict = projectDictService.findByFileId(id);
        return ResponseEntity.ok(fileDict);
    }
}
