package com.jeeplus.finance.projectReportAuditSheet.controller;

import com.jeeplus.finance.projectReport.domain.CwProofreadDetail;
import com.jeeplus.finance.projectReportAuditSheet.domain.CwProofreadType;
import com.jeeplus.finance.projectReportAuditSheet.mapper.CwProofreadTypeMapper;
import com.jeeplus.finance.projectReportAuditSheet.service.CwProofreadTypeForTreeDataService;
import com.jeeplus.finance.projectReportAuditSheet.service.CwProofreadTypeService;
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-12-08 09:13
 **/
@RestController
@Api(tags ="报告审核单")
@RequestMapping(value = "/auditSheet/type")
public class AuditSheetTypeController {

    @Resource
    private CwProofreadTypeService service;

    @Resource
    private CwProofreadTypeMapper mapper;

    @Resource
    private CwProofreadTypeForTreeDataService treeDataService;

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

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

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping("/findById")
    public ResponseEntity<CwProofreadType> findById(String id) {
        CwProofreadType 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<CwProofreadType>> treeData(@RequestParam(required = false) String extId, @RequestParam(required = false) String type) throws Exception{
        List<CwProofreadType> infos = treeDataService.treeDataForType(extId, type);
        return ResponseEntity.ok(infos);
    }

    /**
     * 初始化类型列表查询
     * @return
     */
    @ApiOperation(value = "初始化类型列表查询")
    @GetMapping("/prooList")
    public ResponseEntity<List<CwProofreadDetail>> list(@RequestParam(value="type") String type) {
        List<CwProofreadDetail> list = service.prooList(type);
        return ResponseEntity.ok(list);
    }
}
