package com.dayou.controller;

import com.dayou.bo.ReportNounBO;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.controller.BaseController;
import com.dayou.service.IReportNounService;
import com.dayou.entity.ReportNoun;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.common.PullDownModel;
import com.dayou.utils.ConvertUtil;
import com.dayou.utils.HttpKit;
import com.dayou.exception.ErrorCode;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
/**
 * 报告名词占位符
 *
 * @author wucl
 * @since 2023-09-05
 */
@RestController
@RequestMapping("reportNoun")
@Slf4j
public class ReportNounController extends BaseController {
    @Autowired
    private IReportNounService reportNounService;

    /**
    * 报告名词占位符列表
    */
    @GetMapping("/list/{id}")
    public RestResponse<List<ReportNounBO>> getListByType(@PathVariable("reportType") String reportType){
        List<ReportNounBO> list = reportNounService.getListByType(reportType);
        return RestResponse.data(list);
    }

    /**
     * 报告名词占位符详情
     */
    @GetMapping("/{id}")
    public RestResponse<ReportNoun> detail(@PathVariable Long id){
        ReportNoun xReportNoun =reportNounService.detail(id);
        return RestResponse.data(xReportNoun);
     }

    /**
     * 报告名词占位符新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ReportNoun reportNoun) {
        Boolean ret = reportNounService.add(reportNoun);
        return RestResponse.data(ret);
    }

    /**
     * 报告名词占位符更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody ReportNoun reportNoun) {
        Boolean ret = reportNounService.update(reportNoun);
        return RestResponse.data(ret);
    }

    /**
     * 报告名词占位符删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = reportNounService.delete(id);
        return RestResponse.data(ret);
    }


    /**
     * 报告名词占位符下拉列表
     */
    @GetMapping("/simpleAll")
    public RestResponse<List<PullDownModel>> simpleAll(){
        LambdaQueryWrapper<ReportNoun> lambdaQueryWrapper = new LambdaQueryWrapper<ReportNoun>()
        .select(ReportNoun::getId,ReportNoun::getName)
        .eq(ReportNoun::getDeleted,false);
        List<ReportNoun> list= reportNounService.list(lambdaQueryWrapper);
        List<PullDownModel> ret=ConvertUtil.copyList(list, PullDownModel.class);
        return RestResponse.data(ret);
    }
}

